Reputation: 8727
In PyCharm I have one project that makes calls to another project's modules.
For example let's say we have two projects abc and xyz. Within project abc we have a module abc.mod_a with function f1(), and within project xyz we have a module xyz.mod_b with function f2().
abc.mod_a.py:
import xyz.mod_b
def f1():
xyz.mod_b.f2()
xyz.mod_b.py:
def f2():
print("something was done")
I've done the following to make this possible:
I have added xyz as a project dependency for project abc: Settings->Project->Project Dependencies
I have added the path to xyz's primary directory to the PYTHONPATH for the interpreter used for project abc: Settings->Project->Project Interpreter->Show All->Interpreter Paths->Add Path
When I run code that uses abc.mod_a.py I get a module not found error on the initial import xyz statement. What am I doing wrong?
Upvotes: 3
Views: 6746
Reputation: 6320
Easiest way is to work on the abc project and open the xyz project. You get the dialog below.
This will open the xyz inside of your abc project. It will handle all of the dependencies for you.
Another alternative is to install your xyz python library in development mode. https://pip.pypa.io/en/latest/reference/pip_install/#editable-installs
pip install -e ../path_to/xyz
This creates a link in your python's site-packages directory which points to your xyz directory. When you call import xyz.mod_b
it will look in the proper directory.
Upvotes: 6