简体   繁体   中英

How can I mark a python package as resource directory by command in linux?

In Pycharm I can easily mark a directory as a source directory and then import it in other files. But when I run the file with python command in the terminal I've got the import error that indicates the so-called package is not found. How can I solve this issue?

The magic of marking a directory as source in PyCharm comes from the "Add source roots to PYTHONPATH" checkbox in PyCharm's run configuration dialog. When this is checked, then all directories marked as "source" are added to PYTHONPATH.

On the command line, you don't have the infrastructure given by PyCharm. Therefore you need to define a PYTHONPATH yourself. Ie do something like:

PYTHONPATH=dir1:dir2:dir3 python myscript.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM