Solution 28
Force Python to look for packages in the current directory
I am working with BasicSR. I have installed it using pip. I also have a basicsr folder in my code repo. Initially, after installation, python used to consider the local copy as the base. I used to modify the code inside my local copy and it used to work. But for the last couple of days, it has changed, I think it might be because of some package I have recently installed like wandb but I am not sure. Nevertheless, I now know a way to force python to look into current directory for packages and it’s working fine now. Following is the method to achieve the mentioned goal:
Get Talha Hanif Butt’s stories in your inbox
Join Medium for free to get updates from this writer.
On Linux/macOS
export PYTHONPATH=$PYTHONPATH:.
python your_script.py
On Windows (Command Prompt)
set PYTHONPATH=%PYTHONPATH%;.
python your_script.py
In PyCharm
To fix this in PyCharm, you don’t need to change your code. You can fix it directly through PyCharm’s project
Mark your root folder as “Sources Root”
PyCharm has a built-in feature to tell Python exactly where your local codebase lives.
1. In the Project tool window (usually on the left), locate the parent folder that contains your local basicsr folder.
2. Right-click that parent folder.
3. Hover over Mark Directory as.
4. Click Sources Root.
(The folder icon will turn blue, telling PyCharm to automatically add this folder to your PYTHONPATH whenever you run code).
That’s it for now. See you later.





