Python Adds a Search Path
1. Additions to the program
Use to add, for example.
import sys ('/Users/username/Documents/')
and can be used to export the currently contained directories.
2. Additions using .pth files
Add a .pth file to the lib/python/site-packages/ directory in the directory where lib/python is installed.
It is important to note where python is installed.
For example, to use the my_project environment with the virtual environment in conda, add a file to the /Users/username/opt/anaconda3/envs/fealpy/lib/python3.8/site-packages directory.
is the directory that will be added.
/Users/username/Documents/ /Users/username/Downloads/
Once added, it can also be called in python to see.
import sys
P.S. Python temporarily adds search paths
Put the address where your project is located inside the list for quick import of modules.
import os, sys
# Get the current user's home directory module = ('~') # Print the current user's home directory print(module) # Define the search priority for the home directory, with 0 being the highest priority. # () adds a temporary search path as well, which expires when the program exits. (0, module) # Print search path print()
summarize
to this article on Python to add a search path to this article, more related to Python to add a search path content please search my previous posts or continue to browse the following related articles I hope that you will support me more in the future!