尝试使用pip安装flask时出现解析器错误
我在我的根目录下安装了Flask,不过每次我切换目录并运行虚拟环境命令(virtualenv venv)来尝试通过pip安装Flask时,都会收到以下错误信息:
bash: /home/phillipsk/rampup/sql/venv/bin/easy_install: /home/phillipsk/rampup/webapp/sql/venv/bin/python: bad interpreter: No such file or directory
这是我虚拟环境(venv)目录里的内容:
activate activate.csh activate.fish activate_this.py easy_install easy_install-2.7 pip pip2 pip2.7 python python2 python2.7
我可以运行这个命令:
/home/phillipsk/rampup/webapp/sql/venv/bin/python
然后Python解释器就打开了:
Python 2.7.6
这是我运行的命令的详细信息:
/home/phillipsk/rampup/webapp/sql/venv/bin/python
-rwxr-xr-x 1 root root 3349512 Aug 15 13:11 /home/phillipsk/rampup/webapp/sql/venv/bin/python
这是我尝试运行的命令:
> (venv)phillipsk@phillips:~/rampup/webapp/sql/venv/bin$ pip install flask Downloading/unpacking flask Cleaning up... Exception: Traceback
> (most recent call last): File
> "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/basecommand.py",
> line 122, in main
> status = self.run(options, args) File "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/commands/install.py",
> line 278, in run
> requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle) File
> "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/req.py",
> line 1153, in prepare_files
> location = req_to_install.build_location(self.build_dir, not self.is_download) File
> "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/req.py",
> line 218, in build_location
> _make_build_dir(build_dir) File "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/req.py",
> line 1527, in _make_build_dir
> os.makedirs(build_dir) File "/home/phillipsk/rampup/webapp/sql/venv/lib/python2.7/os.py", line
> 157, in makedirs
> mkdir(name, mode) OSError: [Errno 13] Permission denied: '/home/phillipsk/rampup/webapp/sql/venv/build'
>
> Storing debug log for failure in /home/phillipsk/.pip/pip.log
sudo pip install flask
这个命令是可以执行的,但无论我运行哪个pip命令,之后我都会直接进入Python解释器,然后尝试用import flask
,但都没有成功。
2 个回答
这个文件夹是由根用户(root)拥有的,你自己也说过。
-rwxr-xr-x 1 root root 3349512 Aug 15 13:11 /home/phillipsk/rampup/webapp/sql/venv/bin/python
所以要做到这一点,只需要
sudo pip install flask
作为一个临时解决办法,试着改变你 venv 文件夹以及里面所有文件和文件夹的拥有权:
sudo chown -R yourusername:yourusersgroup venv
然后重新激活虚拟环境,再试着不使用 sudo 来安装 flask。
顺便说一下,如果你在创建虚拟环境的时候使用了 sudo,其实是不应该的。你应该以普通用户的身份运行 virtualenv /path/to/virtualenv,然后激活它,再用 pip install 来安装需要的东西。希望这对你有帮助。
另外,可以看看 virtualenvwrapper 这个项目。它可能会让你将来的工作变得更简单。 http://virtualenvwrapper.readthedocs.org/en/latest/