Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PYTHONPATH vs symbolic link

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…

  1. I don't have to repeat myself; and…
  2. both the Python interpreter and PyCharm would be aware of it?
like image 605
Kal Avatar asked Feb 01 '13 13:02

Kal


People also ask

What is the use of Pythonpath?

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.

Is Python a symlink?

symlink() method in Python is used to create symbolic link.

How do you check if a file is a soft link in Python?

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.


1 Answers

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.

like image 192
Hugo Tavares Avatar answered Sep 26 '22 02:09

Hugo Tavares