So I have been fiddling around as well as conducting some serious work with Python for quite some time. Though, I still have some issues with it every once in a while.
I find it to be the most comfortable using PyCharm CE
when working with Python. The typical scenario is that I just create a new virtualenv
, launch PyCharm and open up my virtualenv
there. And from there on out, it's like on auto-pilot, PyCharm handles all the dirty work related to which site-packages
and Python runtime to use.
I always like to keep my virtualenv
s clean and organized, so I often find myself semantically organizing my source code into submodules/subfolders. So whenever I want to import some code, or class, or whatever from another folder I just import it.
Imagine I have the following structure in my virtualenv
:
├── bin
├── include
├── lib
└── src
├── foo.py
├── important_scripts
├── some_script.py
└── some_other_script.py
└── pip-selfcheck.json
Now, somewhere in foo.py
, I want to use a function named A()
that is implemented in some_script.py
. The obvious way would be to add a simple line to foo.py
- something like from some_script import A
. Doing such works perfectly when I run and debug my code (foo.py
in this case) from PyCharm.
As opposed to the the typical scenario I have described above, I wanted to do the same from the Terminal.app
. So I fire up the Terminal, cd
to my virtualenv
and activate it. Then, what I do is, using the Python executable that is under the bin
folder in my virtualenv
, I try to run foo.py
(At least this is what I think is the equivalent of right-clicking and running foo.py
from the PyCharm window). Unfortunately, I get the error ModuleNotFoundError: No module named 'some_script'
.
I think I am missing a simple detail or something. Because like I said, it works like magic when run from PyCharm.
Anyways, any advice or help will be highly appreciated. Thanks in advance.