Import module works in terminal but not in IDLE

前端 未结 6 1661
轮回少年
轮回少年 2020-12-03 21:54

I am trying to import pyodbc module on a windows computer. It works in the terminal, but not the IDLE. The error message in IDLE is:



        
相关标签:
6条回答
  • 2020-12-03 22:20

    I Found the solution. It works for me

    The problem is your installation directory does not match with the python version directory.
    solution is >>>

    1. type %localappdata% in your search bar then go to this folder.
    2. here select the program folder. then select Programs , Python , Python version , Scripts
    3. copy the location of the Scripts folder
    4. open command prompt and type cd //yourpath (in my case cd C:\Users\3C HOUSE\AppData\Local\Programs\Python\Python37\Scripts)
    5. if you wanna install numpy , now run pip install numpy
    0 讨论(0)
  • 2020-12-03 22:22

    You can pip show after install package and know about location where package installed.

    After that check in IDLE sys.path and if directory with package not in sys.path try to add it.

    import sys
    sys.path.append("/home/dm/.local/lib/python3.6/site-packages")
    # or another folder that `pip show` about package.
    
    0 讨论(0)
  • 2020-12-03 22:24

    This typically occurs when multiple versions of python are installed with different paths. You can check to see if you have multiple installations by opening up the IDLE terminal and using

    import sys
    sys.version
    sys.path
    

    These commands will print the system PATH and version of the current instance of python. Use this in both IDLE and the command line terminal to see where each differ. Once you know which version is the one you want then just remove the other. You could also remove all python instances and then reinstall a clean python environment but then you would have to re-install all of your modules using pip or easy_install

    0 讨论(0)
  • 2020-12-03 22:24

    this happen because of multiple python installed (32bit version, 64bit version) or 3v and 2.7v so to solve this problem you have to invoke the idle for that specific version like this

    cd to the dir of the version that the import work fine in cmd in that folder type this command below

    pythonw.exe Lib\idlelib\idle.pyw
    

    this command will invoke idle for that version and the import will work fine

    0 讨论(0)
  • 2020-12-03 22:33

    When you put your python scripts that have import pandas in the same folder as the site packages like pandas for example and use the same version of python that is used on CMD, it should help run your scripts in IDLE.

    0 讨论(0)
  • 2020-12-03 22:34
    1. Open python in cmd (type python and press enter)
    2. Import the module in cmd (type import modulename)
    3. Type modulename.__file__
    4. You will get the path where the module is stored
    5. Copy the corresponding folder
    6. In IDLE, import sys and typing sys.executable to get the paths where it looks for modules to import
    7. Paste your module's folder in the path where IDLE looks for modules.

    This method worked for me.

    0 讨论(0)
提交回复
热议问题