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?
The default places where Python looks for packages are as follows:
The
site-packages
directoryEnvironment variable
PYTHONPATH
directoryCurrent directory
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 addC:
to thePYTHONPATH
environment variable in the above method.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