import error: 'No module named' *does* exist

前端 未结 11 1655
星月不相逢
星月不相逢 2020-11-29 04:30

I am getting this stack trace when I start pyramid pserve:

% python $(which pserve) ../etc/development.ini
Traceback         


        
11条回答
  •  渐次进展
    2020-11-29 04:46

    They are several ways to run python script:

    • run by double click on file.py (it opens the python command line)
    • run your file.py from the cmd prompt (cmd) (drag/drop your file on it for instance)
    • run your file.py in your IDE (eg. pyscripter or Pycharm)

    Each of these ways can run a different version of python (¤)


    Check which python version is run by cmd: Type in cmd:

    python --version 
    

    Check which python version is run when clicking on .py:

    option 1:

    create a test.py containing this:

    import sys print (sys.version)
    input("exit")
    

    Option 2:

    type in cmd:

    assoc .py
    ftype Python.File
    

    Check the path and if the module (ex: win32clipboard) is recognized in the cmd:

    create a test.py containing this:

    python
    import sys
    sys.executable
    sys.path
    import win32clipboard
    win32clipboard.__file__
    

    Check the path and if module is recognized in the .py

    create a test.py containing this:

    import sys
    print(sys.executable)
    print(sys.path)
    import win32clipboard
    print(win32clipboard.__file__)
    

    If the version in cmd is ok but not in .py it's because the default program associated with .py isn't the right one. Change python version for .py

    To change the python version associated with cmd:

    Control Panel\All Control Panel Items\System\Advanced system setting\Environnement variable In SYSTEM variable set the path variable to you python version (the path are separated by ;: cmd use the FIRST path eg: C:\path\to\Python27;C:\path\to\Python35 → cmd will use python27)

    To change the python version associated with .py extension:

    Run cmd as admin:

    Write: ftype Python.File="C:\Python35\python.exe" "%1" %* It will set the last python version (eg. python3.6). If your last version is 3.6 but you want 3.5 just add some xxx in your folder (xxxpython36) so it will take the last recognized version which is python3.5 (after the cmd remove the xxx).

    Other:

    "No modul error" could also come from a syntax error btw python et 3 (eg. missing parenthesis for print function...)

    ¤ Thus each of them has it's own pip version

提交回复
热议问题