我确实在我的根目录下安装了 Flask,但是每当我更改目录并运行 virutalenv venv 以尝试通过 pip install flask 安装 flask 时,我都会收到以下错误
bash:/home/phillipsk/rampup/sql/venv/bin/easy_install:/home/phillipsk/rampup/webapp/sql/venv/bin/python: 错误的解释器: 没有这样的文件或目录
这里是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
这是 ls -l 的
/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
这是我尝试运行 pip install flask
> (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
但没有成功
最佳答案
作为临时解决方案,请尝试更改您的 venv 文件夹以及所有底层文件和文件夹的所有权:
sudo chown -R yourusername:yourusersgroup venv
然后重新激活 virtualenv 并尝试在没有 sudo 的情况下安装 flask。
顺便说一句。如果你在创建 virtualenvs 时使用 sudo,你不应该。在没有 sudo 的情况下运行 virtualenv/path/to/virtualenv 并以普通用户身份登录,激活它,然后 pip install 东西。希望这会有所帮助。
作为旁注查看virtualenvwrapper 项目。它可能会让你将来的事情变得更容易。 http://virtualenvwrapper.readthedocs.org/en/latest/
关于python - 尝试 pip install flask 时解释器不好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25320013/