J'ai suivi ce tutoriel pour installer python2.7 sur mes CentOS 5.5: http://villaroad.com/2010/10/rolling-python-2-6-2-on-centos-5-3/Python ne "voit" un paquet
Après l'installation de python 2.7 J'ai:
/opt/python2.7$ ls -la
total 24
drwxr-xr-x 6 root root 4096 2011-10-01 22:32 .
drwxr-xr-x 4 root root 4096 2011-10-01 22:32 ..
drwxr-xr-x 2 root root 4096 2011-10-09 19:51 bin
drwxr-xr-x 3 root root 4096 2011-10-01 22:32 include
drwxr-xr-x 4 root root 4096 2011-10-01 23:34 lib
drwxr-xr-x 3 root root 4096 2011-10-01 22:32 share
/opt/python2.7$ ls -la bin
total 88
drwxr-xr-x 2 root root 4096 2011-10-09 19:51 .
drwxr-xr-x 6 root root 4096 2011-10-01 22:32 ..
-rwxr-xr-x 1 root root 105 2011-10-01 22:32 2to3
-rwxr-xr-x 1 root root 296 2011-10-09 19:49 easy_install
-rwxr-xr-x 1 root root 304 2011-10-09 19:49 easy_install-2.7
-rwxr-xr-x 1 root root 103 2011-10-01 22:32 idle
-rwxr-xr-x 1 root root 254 2011-10-03 01:37 pip
-rwxr-xr-x 1 root root 262 2011-10-03 01:37 pip-2.7
-rwxr-xr-x 1 root root 88 2011-10-01 22:32 pydoc
-rwxr-xr-x 2 root root 11783 2011-10-01 23:34 python
-rwxr-xr-x 2 root root 11783 2011-10-01 23:34 python2.7
-rwxr-xr-x 1 root root 1628 2011-10-01 23:34 python2.7-config
lrwxrwxrwx 1 root root 16 2011-10-01 23:34 python-config -> python2.7-config
-rwxr-xr-x 1 root root 18551 2011-10-01 22:32 smtpd.py
-rwxr-xr-x 1 root root 289 2011-10-09 19:51 virtualenv
J'utilise /opt/python2.7/bin/virtualenv
binaire pour créer un environnement dans /var/www/myproj/env
cd /var/www/myproj
virtualenv --no-site-packages -p /opt/python2.7/bin/python \
--clear --prompt="(myproj.com) " env
Activer, et ne Pip flacon d'installation. installes pépin flacon à env/lib/python2.7/site-packages
et ce n'est pas sur sys.path
$ python
Python 2.7.2 (default, Oct 1 2011, 23:29:08)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named flask
>>> import sys
>>> sys.path
['', '/opt/python2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/opt/python2.7/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
'/opt/python2.7/lib/python27.zip', '/opt/python2.7/lib/python2.7',
'/opt/python2.7/lib/python2.7/plat-linux2', '/opt/python2.7/lib/python2.7/lib-tk',
'/opt/python2.7/lib/python2.7/lib-old', '/opt/python2.7/lib/python2.7/lib-dynload',
'/opt/python2.7/lib/python2.7/site-packages']
J'ai essayé la même chose, mais en utilisant easy_install
au lieu de pip
- même résultat.
Flask est installé sous env/lib/python2.7/site-packages
, donc la question principale est: ne pas virtualenv
devez ajouter env/lib/python2.7/site-packages
au chemin sys de python? Sinon, que dois-je faire mieux:
- ajouter un répertoire site-packages appropriés sur le chemin de python à l'exécution (par exemple
sys.path.insert(0, <path to site-packages>)
dans mon application flacon, - modifier méthode du système
PYTHONPATH
ou - déclencheur de virtualenv
after_install
à ajouter<path to site-packages>
au chemin de python
un peu plus d'info: J'ai ajouté chez l'utilisateur et la racine ~/.bash_profile (~/.profile sur Ubuntu)
alias python='/opt/python2.7/bin/python'
alias python2.7='/opt/python2.7/bin/python'
PATH=$PATH:/opt/python2.7/bin
a fait source ~/.profile
qui python produit /usr/bin/python
qui est 2.6.4 (hmmmm ...)
Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
assez étrange, mais si je cours python
je reçois la bonne version:
$ python
Python 2.7.2 (default, Oct 1 2011, 23:29:08)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
ce qui est encore plus étrange est que après avoir suivi le tutoriel d'installation de python2.7, j'obtenais /opt/python2.7/bin/python
sur la commande which python
. Quoi qu'il en soit, la question est là, toute aide est appréciée. S'il vous plaît, considérez que je suis un débutant python, - c'est probablement une question stupide que je pose ici.
Merci pour grande justification sur ce qui se passe. En effet, j'ai dû appeler 'env/bin/python',' quel python' dit que binaire python est là, ** MAIS ** j'ai foiré avec 'alias python ="/chemin/vers/python2.7 "' et donc le système sait que 'python' est un alias pour'/opt/python2.7/bin/python', pas le binaire approprié! Oh, mon garçon, tant de maux de tête à cause de mes mains tordues :-) Sur un certain niveau, j'ai senti que l'alias était une mauvaise idée, mais je me suis contenté de ce tutoriel ... – Nemoden
Oui, le tutoriel est assez ancien. écrit avant que «virtualenv» existe, puis patché à la hâte pour Python 2.7. 'virtualenv' a été créé précisément pour rendre ces choses plus faciles :) –