Problem importing libraries installed with PIP in Eclipse


R

Renato

Hi guys, I'm using Python 2.7.5 64 bits and I have a problem when importinglibraries that were installed via PIP when importing them inside Eclipse (version 4.3.1). Outside Eclipse (directly in Python's shell) everything works fine, here is an example:

Everything works outside Eclipse. But inside Eclipse I can't import libraries installed via PIP using "from x import y" format, it will give an error.The only way I can import libraries installed via PIP is using "import x" format. Here is an example:

import numpy # no errors (installed from repositories)
from numpy import array # no errors
import pybrain # no errors (installed viaPIP)
from pybrain import Network # gives the error below

Traceback (most recent call last):
File "/media/arquivos/pybrain_import_test.py", line 4, in <module>
from pybrain import Network
ImportError: cannot import name Network

I suspected it could be related to virtualenv, but here is a print screen (http://imageshack.com/a/img534/4307/3x0m.png) of my Python's PATH. The directory /usr/lib/python2.7/site-packages where PyBrain is installed is already in Python's PATH inside Eclipse. Could someone help me, please?
 
Ad

Advertisements

F

Fabio Zadrozny

Hi guys, I'm using Python 2.7.5 64 bits and I have a problem when
importing libraries that were installed via PIP when importing them inside
Eclipse (version 4.3.1). Outside Eclipse (directly in Python's shell)
everything works fine, here is an example:


Everything works outside Eclipse. But inside Eclipse I can't import
libraries installed via PIP using "from x import y" format, it will give an
error. The only way I can import libraries installed via PIP is using
"import x" format. Here is an example:

import numpy # no errors (installed
from repositories)
from numpy import array # no errors
import pybrain # no errors (installed
via PIP)
from pybrain import Network # gives the error below

Traceback (most recent call last):
File "/media/arquivos/pybrain_import_test.py", line 4, in <module>
from pybrain import Network
ImportError: cannot import name Network

I suspected it could be related to virtualenv, but here is a print screen (
http://imageshack.com/a/img534/4307/3x0m.png) of my Python's PATH. The
directory /usr/lib/python2.7/site-packages where PyBrain is installed is
already in Python's PATH inside Eclipse. Could someone help me, please?

Hi Renato,

Can you do the following:

Create a new script with:

import sys
print '\n'.join(sorted(sys.path))

And let me know if the paths you have listed in both are equal... Also,
which version of PyDev are you using?

Cheers,

Fabio
 
R

Renato

Em sexta-feira, 14 de fevereiro de 2014 01h30min05s UTC-2, Renato escreveu:
Hi guys, I'm using Python 2.7.5 64 bits and I have a problem when importing libraries that were installed via PIP when importing them inside Eclipse(version 4.3.1). Outside Eclipse (directly in Python's shell) everything works fine, here is an example:






Everything works outside Eclipse. But inside Eclipse I can't import libraries installed via PIP using "from x import y" format, it will give an error. The only way I can import libraries installed via PIP is using "import x" format. Here is an example:



import numpy # no errors (installed from repositories)

from numpy import array # no errors

import pybrain # no errors (installed via PIP)

from pybrain import Network # gives the error below



Traceback (most recent call last):

File "/media/arquivos/pybrain_import_test.py", line 4, in <module>

from pybrain import Network

ImportError: cannot import name Network



I suspected it could be related to virtualenv, but here is a print screen(http://imageshack.com/a/img534/4307/3x0m.png) of my Python's PATH. The directory /usr/lib/python2.7/site-packages where PyBrain is installed is already in Python's PATH inside Eclipse. Could someone help me, please?


Fabio, thanks for your reply. I'm using PyDev version 2.7.0.2013032300, theone who comes with Aptana Studio plugin for Eclipse. Here is Eclipse output:

/media/arquivos/Documentos/Programacao/Source/workspace_linux/Testes em Python/src
/media/arquivos/Documentos/Programacao/Source/workspace_linux/Testes em Python/src/pip_eclipse
/usr/lib/python2.7/site-packages
/usr/lib/python27.zip
/usr/lib64/python2.7
/usr/lib64/python2.7/lib-dynload
/usr/lib64/python2.7/lib-old
/usr/lib64/python2.7/lib-tk
/usr/lib64/python2.7/plat-linux2
/usr/lib64/python2.7/site-packages
/usr/lib64/python2.7/site-packages/PIL
/usr/lib64/python2.7/site-packages/gtk-2.0
/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode
/usr/local/lib/python2.7/site-packages
/usr/local/lib/python2.7/site-packages
/usr/local/lib64/python2.7/site-packages
/usr/local/lib64/python2.7/site-packages

And here is Python shell output:

/usr/lib/python2.7/site-packages
/usr/lib/python27.zip
/usr/lib64/python2.7
/usr/lib64/python2.7/lib-dynload
/usr/lib64/python2.7/lib-old
/usr/lib64/python2.7/lib-tk
/usr/lib64/python2.7/plat-linux2
/usr/lib64/python2.7/site-packages
/usr/lib64/python2.7/site-packages/PIL
/usr/lib64/python2.7/site-packages/gtk-2.0
/usr/lib64/python2.7/site-packages/wx-2.8-gtk2-unicode
/usr/local/lib/python2.7/site-packages
/usr/local/lib64/python2.7/site-packages

They are almost exactly the same, the only difference is that Eclipse includes the directory I'm running the script and print twice the last 2 directories.
 
R

Renato

It's solved now, oh my god I was so stupid! I created a package named "pybrain" for testing PyBrain module, so obviously when I tryed to import something from PyBrain library, Python would import all modules from this personal package I created. The problem was not being reproduced outside Eclipse because only within Eclipse my personal workstation directory (which contained the personal package "pybrain") was visible. The solution was simple: I just deleted the personal package named "pybrain" and now everything is working. Thank you very much for your help!
 
F

Fabio Zadrozny

It's solved now, oh my god I was so stupid! I created a package named
"pybrain" for testing PyBrain module, so obviously when I tryed to import
something from PyBrain library, Python would import all modules from this
personal package I created. The problem was not being reproduced outside
Eclipse because only within Eclipse my personal workstation directory
(which contained the personal package "pybrain") was visible. The solution
was simple: I just deleted the personal package named "pybrain" and now
everything is working. Thank you very much for your help!


Hi Renato,

Nice that you got it working...

Now, just as a heads up, that version of PyDev is quite old (the latest
PyDev release: 3.3.3 is in many ways improved when comparing to older PyDev
versions). I know Aptana Studio still has the older version, so, if you use
mostly Python and you don't need the other features that Aptana Studio
adds, it might be worth going to pure Eclipse + PyDev (or using LiClipse
which also adds support for other languages -- besides being better
configured out of the box, although it's a commercial counterpart of PyDev
-- whose funds help to keep PyDev development going forward).

Cheers,

Fabio
 
Ad

Advertisements

R

Renato Vernucio

Hi Fabio,

I wish I could use the latest PyDev, unfortunately I need Aptana studio.
It's a pity they won't let us install individual packages from their
bundle. If they did, I could install only the other packages and install
PyDev separately.

Thanks for your help once again.

Yours,
Renato
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top