![]() So you don't need to restart python each time you make some change in your python module for example "project_01". Note: another interessting tool is to be able to reload your python (> 3.4) module: import importlib importlib.reload(module) It will then add automatically "/Users/John/github_projects" to your PYTHONPATH each time you open a new terminal window. bash_profileįile and add the following line: export PYTHONPATH="/Users/John/github_projects" It should have now: "/Users/John/github_projects"Īnd you can now start python (in the same window that you entered "export PYTHONPATH="/Users/John/github_projects") and try to import your module: > import project_01Īnother solution to make that more permanently just open the. To temporary add a new path in your PYTHONPATH: export PYTHONPATH="/Users/John/github_projects" To add a new path to your PYTHONPATH it is going to depend on the your shell (I used hereafter bash shell ). In your terminal (not in your python interpreter!). Returns for example in my case: Ĭan also check your PYTHONPATH using os: > import os > os.environĪnother solution to check your PYTHONPATH is to enter directly echo $PYTHONPATH A simple solution to check that is to look at sys.path: > import sys > sys.path We get this error message here because python doesn't know where to find the python module project_01. However, if I try to import a python module from another reperestory on my computer I will get the following error message: > import project_01 Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'project_01' For example, I have on my local computer a reperestory called "github_projects" (located in the following path "/Users/John/github_projects") where I stored all my own python modules that I develop: github_projects/ project_01/ project_02/ project_03/. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |