2014-07-14 7 views
8

Ho un pacchetto Python che ho bisogno di installare nel /usr/lib/python2.7/dist-packages o in qualsiasi altra directory specifica per quella materia.Come utilizzare setuptools per l'installazione in una directory personalizzata?

Ogni volta che eseguire lo script setup.py dà il seguente risultato:

[email protected]:~/som_dir/plugins/abc$python setup.py install 
running install 
running bdist_egg 
running egg_info 
writing abcNewPlugin.egg-info/PKG-INFO 
writing top-level names to abcNewPlugin.egg-info/top_level.txt 
writing dependency_links to abcNewPlugin.egg-info/dependency_links.txt 
writing entry points to abcNewPlugin.egg-info/entry_points.txt 
reading manifest file 'abcNewPlugin.egg-info/SOURCES.txt' 
writing manifest file 'abcNewPlugin.egg-info/SOURCES.txt' 
installing library code to build/bdist.linux-x86_64/egg 
running install_lib 
warning: install_lib: 'build/lib.linux-x86_64-2.7' does not exist -- no Python modules to install 

creating build/bdist.linux-x86_64/egg 
creating build/bdist.linux-x86_64/egg/EGG-INFO 
installing scripts to build/bdist.linux-x86_64/egg/EGG-INFO/scripts 
running install_scripts 
running build_scripts 
creating build/bdist.linux-x86_64/egg/EGG-INFO/scripts 
copying build/scripts-2.7/abc_plugin.py -> build/bdist.linux-x86_64/egg/EGG-INFO/scripts 
changing mode of build/bdist.linux-x86_64/egg/EGG-INFO/scripts/abc_plugin.py to 775 
copying abcNewPlugin.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO 
copying abcNewPlugin.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO 
copying abcNewPlugin.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO 
copying abcNewPlugin.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO 
copying abcNewPlugin.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO 
zip_safe flag not set; analyzing archive contents... 
creating 'dist/abcNewPlugin-0.0-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it 
removing 'build/bdist.linux-x86_64/egg' (and everything under it) 
Processing abcNewPlugin-0.0-py2.7.egg 
Removing /usr/local/lib/python2.7/dist-packages/abcNewPlugin-0.0-py2.7.egg 
Copying abcNewPlugin-0.0-py2.7.egg to /usr/local/lib/python2.7/dist-packages 
abcNewPlugin 0.0 is already the active version in easy-install.pth 
Installing abc_plugin.py script to /usr/local/bin 

Installed /usr/local/lib/python2.7/dist-packages/abcNewPlugin-0.0-py2.7.egg 
Processing dependencies for abcNewPlugin==0.0 
Finished processing dependencies for abcNewPlugin==0.0 

C'è un modo per specificare la directory del pacchetto di installazione in setuptools? Ho provato --install-dir opzione, ma dà un errore:

$sudo python setup.py install --install-dir=/usr/lib/python2.7/dist-packages 
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] 
    or: setup.py --help [cmd1 cmd2 ...] 
    or: setup.py --help-commands 
    or: setup.py cmd --help 

error: option --install-dir not recognized 

non ho potuto usare --prefix opzione.

risposta

9

Poiché il comando python setup.py install è solo una scorciatoia per easy_install, provare a eseguire direttamente, si ha la possibilità --install-dir:

easy_install . --install-dir /usr/lib/python2.7/dist-packages 

È possibile ottenere altre opzioni disponibili con python setup.py install -h, nel caso in cui avete bisogno di qualche altro, ma questi sono piuttosto criptici.

+1

On python3 (almeno) la bandiera è ora '--prefix' invece di' --install-dir' È possibile anche indirizzare l'** user site package ** ('/home/user/.local/lib/python3.5/site-packages') usando '--user' – Nande

1

--install-lib imposta la directory di installazione di un modulo

python setup.py install --install-lib /src/lib/ 
+0

Di solito è meglio spiegare una soluzione invece di pubblicare solo alcune righe di anonimi codice. Puoi leggere [Come scrivere una buona risposta] (https://stackoverflow.com/help/how-to-answer), e anche [Spiegare interamente le risposte basate sul codice] (https://meta.stackexchange.com/domande/114762/spiegando-entirely-% E2% 80% 8C% E2% 80%-risposte 8Bcode-based). Forse potresti specificare PERCHÉ la tua soluzione funziona ... –