Yesterday, I edited the bin/activate
script of my virtualenv so that it sets the PYTHONPATH
environment variable to include a development version of some external package. I had to do this because the setup.py
of the package uses distutils
and does not support the develop
command à la setuptools
. Setting PYTHONPATH
works fine as far as using the Python interpreter in the terminal is concerned.
However, just now I opened the project settings in PyCharm and discovered that PyCharm is unaware of the external package in question - PyCharm lists neither the external package nor its path. Naturally, that's because PyCharm does not (and cannot reliably) parse or source the bin/activate
script. I could manually add the path in the PyCharm project settings, but that means I have to repeat myself (once in bin/activate
, and again in the PyCharm project settings). That's not DRY and that's bad.
Creating, in site-packages
, a symlink that points to the external package is almost perfect. This way, at least the source editor of PyCharm can find the package and so does the Python interpreter in the terminal. However, somehow PyCharm still does not list the package in the project settings and I'm not sure if it's ok to leave it like that.
So how can I add the external package to my virtualenv/project in such a way that…
It is used to set the path for the user-defined modules so that it can be directly imported into a Python program. It is also responsible for handling the default search path for Python Modules. The PYTHONPATH variable holds a string with the name of various directories that need to be added to the sys.
symlink() method in Python is used to create symbolic link.
path. islink() method in Python is used to check whether the given path represents an existing directory entry that is a symbolic link or not. Note: If symbolic links are not supported by the Python runtime then os.
Even when a package is not using setuptools
pip
monkeypatches setup.py
to force it to use setuptools
.
Maybe you can remove that PYTHONPATH
hack and pip install -e /path/to/package
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With