3

I installed a Python module from GitHub. Here is an example of the commands I ran:

cd ~/modules/
git clone https://github.com/user/xyz
cd xyz
python setup.py develop

this installed the the module succesfully in the current folder. Then from some other folder, I did:

cd ~/test
python -c 'import inspect; import xyz; print(inspect.getfile(xyz))'

wich gave the following output:

/home/hakon/modules/xyz/xyz/__init__.py

Now, I decided I wanted to move the install folder. For example,

cd ~/modules/xyz
mv xyz xyz2

But now Python cannot find the module any longer. For example:

cd ~/test
python -c 'import inspect; import xyz; print(inspect.getfile(xyz))'

With output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'xyz'

Questions:

  • Where does Python register the location of modules?
  • How can I update the registry to the new location of the module?
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • 2
    http://stackoverflow.com/questions/15252040/how-does-python-find-a-module-file-if-the-import-statement-only-contains-the-fil – Praveen May 16 '17 at 08:12

1 Answers1

2

According to the documentation for setup tools develop command:

The develop command works by creating an .egg-link file (named for the project) in the given staging area. If the staging area is Python’s site-packages directory, it also updates an easy-install.pth file so that the project is on sys.path by default for all programs run using that Python installation.

So to answer the question to update the location after you have moved the project folder you can rerun the develop command (from the new folder):

python setup.py develop

Note: you could also unregister the project before you moved it:

python setup.py develop --unistall

but this is not necessary if you just want to update the location.

Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174