python3.x - Why can't python find the module even after setting the .pth file?
伊谢尔伦
伊谢尔伦 2017-06-28 09:25:47
0
2
1011

My python is version 3.5.2.
I have a helloworld.py module, which has a show function to output "Hello World". I put this module under the pck folder, and then put the pck folder under the C drive.

Then, I created the PckPath.pth file in the site-packages directory of the python installation path, and tried various writing methods:

  • C:\

  • C:\pck

  • C:\pck\helloworld

  • C:\pck\helloworld.py

  • Replace the above backslash with a forward slash

  • ……..

No matter which one it is, create a new test.py file on the desktop and enter

import pck.helloworld
pck.helloworld.show()

It will prompt in IDLE

Traceback (most recent call last):
  File "C:\Users\Berlin\Desktop\test.py", line 1, in <module>
    import pck.helloworld
ImportError: No module named 'pck

Why? ? If I set sys.path.append(...) directly in test.py, it can be used normally. What is the problem? How to get the .pth file?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
黄舟

The default places where Python looks for packages are as follows:

  1. The site-packages directory

  2. under the Python installation directory
  3. Environment variable PYTHONPATHdirectory

  4. Current directory

  5. sys.path.append(...)Added directory (this is temporary)
    However, if you only put the package under the C drive, then it does not belong to any of the situations. Of course, Python will find it. No more bags. In addition to the sys.path.append() method, it is also possible to add C: to the PYTHONPATH environment variable in the above method.

Ty80

Any language is almost always in this order from system variables, language setting variables to the final real-time recorded variables. For the same variable, the latest one is effective. This is how I check the environment for learning these languages ​​and so on, and I’ll be sure of everything

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template