我在我的Amazon Linux AMI上创建了一个virtualenv(ID_LIKE =" rhel fedora",VERSION =" 2016.09")并运行pip install flask
。但是当我调用python
并运行import flask
时,我得到:
(env)$ python
Python 2.7.12 (default, Sep 1 2016, 22:14:00)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dspitzer/dev/python/Lonestar/env/local/lib/python2.7/dist-packages/flask/__init__.py", line 19, in <module>
from jinja2 import Markup, escape
File "/home/dspitzer/dev/python/Lonestar/env/local/lib/python2.7/dist-packages/jinja2/__init__.py", line 33, in <module>
from jinja2.environment import Environment, Template
File "/home/dspitzer/dev/python/Lonestar/env/local/lib/python2.7/dist-packages/jinja2/environment.py", line 15, in <module>
from jinja2 import nodes
File "/home/dspitzer/dev/python/Lonestar/env/local/lib/python2.7/dist-packages/jinja2/nodes.py", line 19, in <module>
from jinja2.utils import Markup
File "/home/dspitzer/dev/python/Lonestar/env/local/lib/python2.7/dist-packages/jinja2/utils.py", line 624, in <module>
from markupsafe import Markup, escape, soft_unicode
ImportError: No module named markupsafe
>>>
所以我尝试了pip install markupsafe
。它似乎有效:
(env)$ pip install markupsafe
Collecting markupsafe
Using cached MarkupSafe-1.0.tar.gz
Installing collected packages: markupsafe
Running setup.py install for markupsafe
building 'markupsafe._speedups' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c markupsafe/_speedups.c -o build/temp.linux-x86_64-2.7/markupsafe/_speedups.o
gcc -pthread -shared build/temp.linux-x86_64-2.7/markupsafe/_speedups.o -L/usr/lib64 -lpython2.7 -o build/lib.linux-x86_64-2.7/markupsafe/_speedups.so
Successfully installed markupsafe
...但我仍然得到&#34; ImportError:没有名为markupsafe的模块&#34;当我import flask
。
我从https://pypi.python.org/pypi/MarkupSafe下载MarkupSafe-1.0.tar.gz
并且(我的virtualenv仍然激活)我运行了python setup.py install
:
(env)$ python setup.py install
running install
Checking .pth file support in /home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages/
/home/dspitzer/dev/python/Lonestar/env/bin/python -E -c pass
TEST FAILED: /home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages/
and your PYTHONPATH environment variable currently contains:
''
Here are some of your options for correcting the problem:
* You can choose a different installation directory, i.e., one that is
on PYTHONPATH or supports .pth files
* You can add the installation directory to the PYTHONPATH environment
variable. (It must then also be on PYTHONPATH whenever you run
Python and want to use the package(s) you are installing.)
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations
Please make the appropriate changes for your system and try again.
现在该怎么办?运行sudo python setup.py install
可能有效,但MarkupSafe没有安装到我的virtualenv中。
更新:出于绝望(因为我被阻止了),我跑了:
(env)$ export PYTHONPATH=/home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages/
(env)$ python setup.py install
running install
running bdist_egg
running egg_info
writing MarkupSafe.egg-info/PKG-INFO
writing top-level names to MarkupSafe.egg-info/top_level.txt
writing dependency_links to MarkupSafe.egg-info/dependency_links.txt
reading manifest file 'MarkupSafe.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'MarkupSafe.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/markupsafe
copying build/lib.linux-x86_64-2.7/markupsafe/_speedups.c -> build/bdist.linux-x86_64/egg/markupsafe
copying build/lib.linux-x86_64-2.7/markupsafe/_constants.py -> build/bdist.linux-x86_64/egg/markupsafe
copying build/lib.linux-x86_64-2.7/markupsafe/_native.py -> build/bdist.linux-x86_64/egg/markupsafe
copying build/lib.linux-x86_64-2.7/markupsafe/_speedups.so -> build/bdist.linux-x86_64/egg/markupsafe
copying build/lib.linux-x86_64-2.7/markupsafe/_compat.py -> build/bdist.linux-x86_64/egg/markupsafe
copying build/lib.linux-x86_64-2.7/markupsafe/__init__.py -> build/bdist.linux-x86_64/egg/markupsafe
byte-compiling build/bdist.linux-x86_64/egg/markupsafe/_constants.py to _constants.pyc
byte-compiling build/bdist.linux-x86_64/egg/markupsafe/_native.py to _native.pyc
byte-compiling build/bdist.linux-x86_64/egg/markupsafe/_compat.py to _compat.pyc
byte-compiling build/bdist.linux-x86_64/egg/markupsafe/__init__.py to __init__.pyc
creating stub loader for markupsafe/_speedups.so
byte-compiling build/bdist.linux-x86_64/egg/markupsafe/_speedups.py to _speedups.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying MarkupSafe.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MarkupSafe.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MarkupSafe.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MarkupSafe.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying MarkupSafe.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
creating 'dist/MarkupSafe-1.0-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Creating /home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages/site.py
Processing MarkupSafe-1.0-py2.7-linux-x86_64.egg
creating /home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages/MarkupSafe-1.0-py2.7-linux-x86_64.egg
Extracting MarkupSafe-1.0-py2.7-linux-x86_64.egg to /home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages
Adding MarkupSafe 1.0 to easy-install.pth file
Installed /home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages/MarkupSafe-1.0-py2.7-linux-x86_64.egg
Processing dependencies for MarkupSafe==1.0
Finished processing dependencies for MarkupSafe==1.0
现在import flask
有效,但前提是我确定PYTHONPATH=/home/dspitzer/dev/python/Lonestar/env/lib64/python2.7/dist-packages/
。