3

os.chdir()私は、recommendation.py ファイルがある現在のディレクトリを変更するために使用します。次に、入力Import recommendationsするとエラーが発生します。

ImportError: No module named recommendations.

何が問題なのですか?

4

2 に答える 2

5

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())
于 2011-11-26T22:48:02.163 に答える
2

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.

于 2011-11-26T22:48:40.810 に答える