问题
I have a USB with a python installation that I carry around with me & use on computers that don't have python installed/don't allow you to install modules. I'd like to install a python package onto it but have been having trouble. Let me use the package rebound-cli
for example.
If I pip install rebound-cli
, the package is installed onto my PC installation of python D:\Program Files (x86)\Python36-32
.
The directory of my USB python installation is H:\.bin\Program Files\Python
.
I've tried the following
pip install rebound-cli -e "H:\.bin\Program Files\Python\Lib\site-packages"
pip install rebound-cli -e "H:\.bin\Program Files\Python"
They both give me the error(s)
Directory 'H:\\.bin\\Program Files\\Python\\Lib\\site-packages' is not installable. File 'setup.py' not found.
Directory 'H:\\.bin\\Program Files\\Python' is not installable. File 'setup.py' not found.
I've also tried
"H:\.bin\Program Files\Python\Scripts\pip.exe" install rebound-cli
But have received the error
Fatal error in launcher: Unable to create process using '"e:\.bin\program files\python\python.exe" "H:\.bin\Program Files\Python\Scripts\pip.exe" install rebound-cli'
回答1:
The package is installed on your PC because you did not explicitly specify which pip
binary to use.
If you execute where pip
, it would display the directory of the pip
binary which is currently active. In your case, it will most likely be in D:
directory.
To install packages in your USB, use h:\<path>\<to>\<pip>\pip install rebound-cli
.
A better option would be, creating a virtual environment in your USB and activating that environment whenever you want to use Python in your USB. Using an environment will save you from the need to explicitly specify the path to pip
/python
binary located in your USB
来源:https://stackoverflow.com/questions/53103727/how-to-pip-install-to-an-external-drive