Calling python setup.py install from another directory

Viewed 3295

I have the following arborescence:

- root_folder <--- I'm here
    - folder
        - setup.py
        - myModule

When I run python setup.py install from folder, myModule is installed properly and I can do import myModule.

Howerver, when I run python folder/setup.py install from root_folder, import myModule fails, I have to call import folder.myModule.

How can I call the setup.py script from another folder but keep the root folder to be the folder containing the setup.py file?

1 Answers

Yes, you can run a setup.py in a different directory by executing Python in a subprocess.

For example, if the folder in which you want to run the setup.py is C:\Program Files\foo, then you can use:

$ python -c "import subprocess,os; os.chdir('C:\Program Files\foo'); subprocess.call(['python','setup.py','install'])"
Related