程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Collection of Python operation problems (long-term update): pycharm can be run, and the terminal reports an error and cannot find the package it created;

編輯:Python

1. PyCharm Can run , But running at the terminal py Code hinting ModuleNotFoundError: No module named ‘xxx‘ resolvent

(1) reason
because PyCharm Start the interpreter (Interpreter) When It will not only be imported into environment variables sys.path Discovered modules , It will also import modules under the current working directory . When you are in IDLE When starting the interpreter in , The current working directory is the project directory , Can smoothly call modules in the same project ;

But when you When starting from the command line , The current working directory is the directory where you started the interpreter ( namely python Installation directory ), If the location is not the project directory , Then the modules in the project directory will not be found .

(2) solve
Add :

import sys
sys.path.append(" Project absolute path ") # Ensure that when the terminal is running , Can be retrieved to the directory

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved