Linux Add pythonpath environment variable

Source: Internet
Author: User

1. Add environment variables to Pythonpath

Export pythonpath= $PYTHONPATH:/home/myproject

View Pythonpath
Echo $PYTHONPATH

You can enter the Python interpreter and print the Sys.path proof to take effect.

After adding an environment variable, this is done in a deep-rooted python file that can be run independently of the project

such as myproject/a/b/c.py

2, if not add the environment variable, directly into the myproject/a/b/file, and then run c.py is not to run, because c.py often refer to a lot of other modules, Python is not automatically put the parent folder Grandfather folder also added to Pythonpath, PYCAHRM can directly right-click to run the reason is to automatically add additional environment variables, the project folder to add to the environment variable.

3, if not add environment variables, directly run myproject/run.py is no problem, here run is directly below the MyProject, because Python automatically added this folder to the environment variable, but does not automatically add the parent grandfather to the environment variable, so Myproject/a/b/c.py is not functioning properly.

4, If you do not add the environment variables and directly run myproject/a/b/c.py, then the method is to use PYTHON-M, PYTHON-M General introduction is directly run the three-party library inside the file, in fact, can be used to run their own written things. Use the method is to go to the MyProject folder, and then Python-m A.B.C will be able to run normally.

This method is good, the environment variable should not be too much, too much, may cause the Python file with the same name to cause conflict.

Linux Add pythonpath environment variable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.