intermodule dependency within the same project via relative path
I'm using IDEA Python plugin but I think this pertains to pycharm as well:
My project has 2 modules. scripts in module2 depend on scripts in module1 eg myscript.py needs to import help.py
I'd like to set a relative 'classpath' in module2 ie: something like $MODULEDIR$../../../../module1/src/py so it knows about the scripts in module1.src.py
I know I can do this by doing sys.path.append( <../../../../module1/src/py ) but don't wish to do that as my deploy mechanism will be different.
Dir Structure:
c:\MyProject
-module1
-src
-py
-helper.py
-module2
-src
-py
-myscript.py #depends on helper.py
I want to do this so that if someone else opens my project but has a different root dir eg c:\workspace\MyProject everything will still work because all the paths are relative to the project.
thanks
Please sign in to leave a comment.
In the Python plugin, you can define a dependency between the modules in Settings | Project Structure. Then the Python plugin will automatically add the dependent modules to the PYTHONPATH.
Thanks Dmitry,
Ive added module1 as a dependency of module2.
does that mean I will have to refer to helper.py via import src.main.py.helper?
that doesn't seem to work for me. importing helper.py doesn't work either. is it looking in a target folder in that module instead?
No, it looks at source roots (if you have any defined) or content roots. Please make sure that the "py" directory is marked as a source root.
Thank you, that makes sense and has worked.
Does Pycharm or the IDEA plugin give me a way of packaging that via a deploy button.
eg. if I write a setup.py will it output the tarball, zip and or msi for me?
You can use the distutils integration for this purpose. You'll need to write a setup.py file describing how your application needs to be packaged.
Sorr yi'm still new to pycharm and IDEA, I tried googling it but did not see any reference to: 'distutils integration' for Pycharm.
can you elaborate please? I do appreiate all your help!
http://www.jetbrains.com/pycharm/webhelp/creating-and-running-setup-py.html