且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在eclipse中添加python模块到pydev导致导入错误?

更新时间:2022-11-02 15:23:53

这是我的问题的解决方案:


  1. 找到你的相应python版本的文件夹 ../ site-packages / 的路径。 (对我来说是 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages / for python 2.6 on my Mac

  2. 打开eclipse首选项并转到 PyDev - > $ b
  3. 在下方框的左侧,点击新建文件夹

  4. 添加导航到 ../


  5. 你应该很好去。 =)



    感谢@all参与者在评论中提供了正确方向的提示。


    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?

    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.