如何将MarkupSafe安装到amazonluxami上的Flask virtualenv中?

2024-06-09 16:50:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的amazonluxami上创建了一个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。似乎有效:

^{pr2}$

…但是当我import flask时,我仍然得到“ImportError:No module named markupsafe”。在

我从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/。在


Tags: topydevbuildenvhomeegglinux