os.chdir()
私は、recommendation.py ファイルがある現在のディレクトリを変更するために使用します。次に、入力Import recommendations
するとエラーが発生します。
ImportError: No module named recommendations.
何が問題なのですか?
os.chdir()
私は、recommendation.py ファイルがある現在のディレクトリを変更するために使用します。次に、入力Import recommendations
するとエラーが発生します。
ImportError: No module named recommendations.
何が問題なのですか?
Python only looks in the initial working directory (and a few other places) by default. If you change the current directory, insert the new working directory into the search path:
sys.path.insert(0, os.getcwd())
Python doesn't use the current working directory to import modules, except insofar as it adds the initial directory to the path when starting up. You need to add the directory to your Python path, either by setting the PYTHONPATH
environment variable or by modifying sys.path
.