我正在尝试使用PIP安装软件包,但它最初对我不起作用,它给出了权限被拒绝的错误,之后当我尝试使用easy_install时,它给了我这个错误: - >
Searching for mezzanine
Reading https://pypi.python.org/simple/mezzanine/
Reading http://github.com/stephenmcd/mezzanine/
Reading http://mezzanine.jupo.org/
Best match: Mezzanine 3.1.8
Downloading https://pypi.python.org/packages/source/M/Mezzanine/Mezzanine-3.1.8.tar.gz#md5=dcc46016b866ea8de1c87fb9dffd9163
Processing Mezzanine-3.1.8.tar.gz
Writing /tmp/easy_install-2cSSS_/Mezzanine-3.1.8/setup.cfg
Running Mezzanine-3.1.8/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2cSSS_/Mezzanine-3.1.8/egg-dist-tmp-uDjreS
Traceback (most recent call last):
File "/usr/local/bin/easy_install", line 8, in ?
sys.exit(
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1924, in main
with_ei_usage(lambda:
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1911, in with_ei_usage
return f()
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1928, in <lambda>
distclass=DistributionWithoutHelpCommands, **kw
File "/usr/local/lib/python2.4/distutils/core.py", line 149, in setup
dist.run_commands()
File "/usr/local/lib/python2.4/distutils/dist.py", line 946, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.4/distutils/dist.py", line 966, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 374, in run
self.easy_install(spec, not self.no_deps)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 609, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 639, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 825, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1031, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1016, in run_setup
run_setup(setup_script, args)
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 68, in run_setup
DirectorySandbox(setup_dir).run(
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 120, in run
return func()
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 71, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 22
with open(e, "r") as f:
^
SyntaxError: invalid syntax
在此之后我再次尝试使用pip然后我得到了不同的错误(未被许可拒绝):
File "/home/rishi/bin/pip", line 8, in ?
sys.exit(
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 357, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 2394, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 2108, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/home/rishi/lib/python2.4/pip-1.5.6-py2.4.egg/pip/__init__.py", line 9, in ?
from pip.log import logger
File "/home/rishi/lib/python2.4/pip-1.5.6-py2.4.egg/pip/log.py", line 19
real_consumer = (consumer if not isinstance(consumer, colorama.AnsiToWin32)
^
SyntaxError: invalid syntax
现在我不知道自己做错了什么,有人可以帮助我吗?
编辑: - 由于错误的python版本,syntex errro解决了,我使用的是2.4。
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/mezzanine'
$ pip结果
~/bin/pip
答案 0 :(得分:3)
只需将--user选项添加到您的pip命令,它将使用您登录的用户权限进行安装:
pip2.7 install mezzanine --user
答案 1 :(得分:2)
sudo
或root
$ sudo pip install mezzanine
这会破坏系统Python,不太推荐。如果您是例如,那将是可以接受的。在Docker下。
$ pip install --user mezzanine
它会将软件包安装到用户方案中,不会破坏系统Python。
这是可以接受的,但很快就会变成凌乱的环境来运行代码,因为Python会从系统中导入表单用户方案。
virtualenv
假设你安装了virtualenv:
$ cd ~/projects
$ mkdir mezza
$ cd mezza
$ virtualenv venv
$ source venv/bin/activate
(venv)$ pip install mezzanine
$ pip freeze
mezzanine==3.1.8
(冻结会有更多的行)。
这将安装到virtualenv中,它很容易重新创建,破坏,并且不会与其他环境混淆。
使用virtulanevwrapper
,您将获得一系列其他工具,这将大大简化您的环境。