Adding python modules to pydev in eclipse results

2020-02-08 06:03发布

I have a problem getting PyDev on eclipse to recognize already installed modules. Here is my detailed approach. The machine is a Mac (Snow Leopard).

In terminal the command

python --version

shows Python 2.6.6.

import unidecode

and

from unidecode import unidecode

work both fine!

I installed PyDev in Eclipse and went to configured the python interpreter (Auto Config). I selected all the proposed packages and hit Apply and Ok.

But eclipse keeps complaining

Traceback (most recent call last):
  File "/Users/me/Documents/workspace/myproject/python/pythontest.py", line 12, in <module>
    from unidecode import unidecode
ImportError: No module named unidecode

The python file looks like this

#!/usr/bin/env python
# encoding: utf-8


import sys
import os
from unidecode import unidecode


def main():
    print unidecode(u"Ågot Aakra")

if __name__ == '__main__':
    main()

When I remove the first line in the script

#!/usr/bin/env python

it results into the same error.

Does someone know where the problem lies?

11条回答
相关推荐>>
2楼-- · 2020-02-08 06:26

I fixed this problem by going to the project properties -> PyDev Django and setting the Django settings module.enter image description here

查看更多
贼婆χ
3楼-- · 2020-02-08 06:29

This is the solution to my problem:

  1. Find out the path to the folder ../site-packages/ of your corresponding python version. ( For me it was /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/ for python 2.6 on my Mac with Snoe Leopard.)
  2. Open eclipse preferences and go to PyDev -> Interpreter - Python.
  3. On the left side of the lower box, click on New Folder.
  4. Add the navigate to ../site-packages/ of your corresponding python version.
  5. Hit open.
  6. Hit Apply.
  7. Hit Ok.

And you should be good to go. =)

Thanks @all particionts, who provided hints into the right direction in the comments.

查看更多
迷人小祖宗
4楼-- · 2020-02-08 06:32

Try preferences > pydev > interpreter - python and removing and re-adding the python interpreter (make sure you know the path to it before you delete it), when you re-add it tick all the boxes.

查看更多
倾城 Initia
5楼-- · 2020-02-08 06:36

In my case I was not getting this error before compiling, but when I compile I got the error ImportError: No module named myant.core. I tried to add the files from PyDev-PYTHONPATH, but again I got the same error. Then I realized that I actually do not have to add the path exactly to the folder where my .py files are located. Infact I have to add the folder where myant.core is located. After doing this I did a restart when I recompiled my project again, the problem was fixed. I would share that I have:

Python 2.7 Eclipse kepler 4.3, PyDev 3.9.2 and on my ubuntu 14.04

.py files location:/${PROJECT_DIR_NAME}/src/myant/core, therefore I added /${PROJECT_DIR_NAME}/src

查看更多
成全新的幸福
6楼-- · 2020-02-08 06:39
  1. Open eclipse window -> preferences and go to PyDev -> Interpreter.
  2. click on 'Check if interpreters are synchronized with environment'

This did it for me. No Eclipse restart was required.

查看更多
登录 后发表回答