Search code examples
pythonlinuxpyramid

Installed module on python cannot be detected by my project


I've installed PyPDF2.

$ sudo pip install PyPDF2

It was successfully installed.

Collecting PyPDF2
Installing collected packages: PyPDF2
Successfully installed PyPDF2-1.26.0

But when I run my project, it produce an error.

ImportError: No module named 'PyPDF2'
Server with PID 19740 exited with code 1.
Waiting for changes before reloading.

Of course my project runs if I comment this module but I need it. For those who can help thanks in advance!

Just for additional info, I'm using Ubuntu 16.04.2 LTS and I'm using Pyramid as my framework (Python).

I try to use

pip install PyPDF2

but

  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/pyPdf'

EDIT: output of pip freeze

adium-theme-ubuntu==0.3.4
beautifulsoup4==4.4.1
Chameleon==2.24
chardet==2.3.0
cryptography==1.2.3
dnspython==1.12.0
enum34==1.1.2
FormEncode==1.3.0
html5lib==0.999
idna==2.0
ipaddress==1.0.16
lxml==3.5.0
Mako==1.0.3
MarkupSafe==0.23
Paste==1.7.5.1
PasteDeploy==1.5.2
PasteScript==1.7.5
pyasn1==0.1.9
pyinotify==0.9.6
pyOpenSSL==0.15.1
PyPDF2==1.26.0
python-openid==2.2.5
repoze.lru==0.6
scgi==1.13
six==1.10.0
Tempita==0.5.2
translationstring==1.3
unity-lens-photos==1.0
venusian==1.0a8
virtualenv==15.1.0
waitress==0.8.10
WebOb==1.5.1
WebTest==2.0.18
zope.component==4.2.2
zope.deprecation==4.1.2
zope.event==4.2.0
zope.hookable==4.0.4
zope.interface==4.1.3

Solution

  • You must install pypdf2 into your virtualenv using the pip connected to that virtualenv.

    env/bin/pip install pypdf2
    

    Anything else will install the package into the wrong environment... sudo pip install would place it into the system's site-packages, and pip install would install it into the system's site-packages but would fail because your user is not root (the only user with access to change the system's site-packages).