Python learning part: pycharm runs smoothly, but terminal runs with various module problems
編輯:Python
Problem description
Many times you use pycharm Use habits , Everything is ready , But it ignores many path problems , Occasionally need to work with other environments 、 When the platform interacts , For example, I wrote a C# Program to call python Excuse for , Equivalent to terminal Start by transmitting parameters , This time will show a variety of No module problem
terms of settlement
The reason is , Because the external environment is calling python At the interface , Go to your program to find each module, But if these module Has not been added to the environment variable , Then you won't find , Therefore, it is recommended to use the following statements in each used py At the beginning of the file
This operation can add the entire upper level directory of the current file to the environment variable , In this way, you can easily call all the files under the upper directory
If you have many levels of directories , The current directory is in a deep location , Then you can change this command a little , In short, include all the files and directories you want to use , Such as can be