简体   繁体   English

如何在Ubuntu16.04上为python3安装Psycopg2

[英]How to install Psycopg2 for python3 on Ubuntu16.04

I have run sudo apt-get install python3-dev and the up-to-date pip. 我已经运行sudo apt-get install python3-dev和最新的pip。

But when I ran pip install psycopg2 , I got this error: 但是当我运行pip install psycopg2 ,出现了此错误:

Collecting psycopg2
  Using cached psycopg2-2.7.1-cp27-cp27mu-manylinux1_x86_64.whl
Installing collected packages: psycopg2
Exception:
Traceback (most recent call last):
  File "/home/flint1025/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/flint1025/.local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/home/flint1025/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/home/flint1025/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/home/flint1025/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/home/flint1025/.local/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/home/flint1025/.local/lib/python2.7/site-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/home/flint1025/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/psycopg2-2.7.1.dist-info'

Then after searching, some solution indicates I should change the ownership of the directory. 然后在搜索之后,一些解决方案表明我应该更改目录的所有权。 So I tried chown -R flint1025:27 /usr/local/lib/python2.7/dist-packages/psycopg2-2.7.1.dist-info but got this error: 所以我尝试了chown -R flint1025:27 /usr/local/lib/python2.7/dist-packages/psycopg2-2.7.1.dist-info但遇到了这个错误:

chown: cannot access '/usr/local/lib/python2.7/dist-packages/psycopg2-2.7.1.dist-info': No such file or directory

What should I do next? 接下来我该怎么办?

Seems like you are not installing in virtualenv ,so you have to use : sudo pip install psycopg2 好像您没有在virtualenv安装,所以您必须使用: sudo pip install psycopg2

Installing package without using virtual environment you need root permissions. 在不使用虚拟环境的情况下安装软件包,您需要root权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM