virtualenv中执行python脚本报错ImportError: No module named markupsafe 或 No such file or directory: '/tmp/tmp0lEZD9/lib/python'

2env为我使用virtualen创建的虚拟python环境,我的本地要使用的各类库已下载到文件夹lianxi下面,ceshi2.txt为我要安装的各类库包列表

(2env) [root@xxxxxxx]$ ./2env/bin/python wsgi.py
Traceback (most recent call last):
File "wsgi.py", line 12, in <module>
from rrd import app
File "/xxxx/rrd/__init__.py", line 4, in <module>
from flask import Flask, request, Blueprint
File "/xxxxx/2env/lib/python2.7/site-packages/flask/__init__.py", line 19, in <module>
from jinja2 import Markup, escape
File "/xxxxx/2env/lib/python2.7/site-packages/jinja2/__init__.py", line 33, in <module>
from jinja2.environment import Environment, Template
File "/xxxxx/2env/lib/python2.7/site-packages/jinja2/environment.py", line 13, in <module>
from jinja2 import nodes
File "/xxxxxx/2env/lib/python2.7/site-packages/jinja2/nodes.py", line 18, in <module>
from jinja2.utils import Markup
File "/xxxxx/2env/lib/python2.7/site-packages/jinja2/utils.py", line 520, in <module>
from markupsafe import Markup, escape, soft_unicode
ImportError: No module named markupsafe
解决办法:
在目录/xxxx/2env/lib/python2.7/site-packages 下确实没有发现markupsafe,需要重新安装,见下面的解决办法
单独重新安装:pip install --no-index --find-links=lianxi -r ./ceshi2.txt --target=2env/lib/python2.7/site-packages
但是执行会出错,见问题2

问题2:
(2env) [root@xxxxx]$ pip install --no-index --find-links=lianxi -r ./ceshi2.txt --target=2env/lib/python2.7/site-packages
Ignoring indexes: https://pypi.python.org/simple
Collecting MarkupSafe==1.1.1 (from -r ./ceshi2.txt (line 1))
Installing collected packages: MarkupSafe
Successfully installed MarkupSafe-1.1.1
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 366, in run
for item in os.listdir(lib_dir):
OSError: [Errno 2] No such file or directory: '/tmp/tmp0lEZD9/lib/python'

解决办法:增加一行lib_dir = lib_dir.replace("lib","lib64")在/usr/lib/python2.7/site-packages/pip/commands/install.py中,增加的位置如下:
if options.target_dir:
ensure_dir(options.target_dir)

lib_dir = distutils_scheme('', home=temp_target_dir)['purelib']
lib_dir = lib_dir.replace("lib","lib64")       <---------------增加到此处
for item in os.listdir(lib_dir):
target_item_dir = os.path.join(options.target_dir, item)
if os.path.exists(target_item_dir):
if not options.upgrade:

 

posted @ 2020-07-01 18:52  天地一体  阅读(1470)  评论(0编辑  收藏  举报