Python find the path to the package (problem solving for custom packages not found)

Source: Internet
Author: User

Problem: Project-Customized packages, Python often cannot find packages when executing python Find the path to the package: the Lib package under the Python installation path and the package under Pythonpath  you can use [Sys.path] to print out the path for Python to find a packageImport SYSSyspath=sys.path  However, when Jenkins runs, it is often prompted to not find the package, so you need to add pythonpath manually, by appending the Sys.path list to implement For example, the following way: Import OSImport SYSrootpath=str ("directory where the project is located")Syspath=sys.path
sys.path=[]
sys.path.append (rootpath) #将工程根目录加入到python搜索路径中
Sys.path.extend ([Rootpath+i for I in Os.listdir (rootpath) if i[0]!= "."]) #将工程目录下的一级目录添加到python搜索路径中sys.path.extend (Syspath) Description: Because I was built with Pycharm a project, I encountered the problem is not found under the project directory, so added the project directory and his next level directory I first use sys.path=[] to clear him, and then append the default path, because I have a package in the project may overlap with other paths, if put in the back of the error. So I put the path in front of it .

Python find the path to the package (problem solving for custom packages not found)

Related Article

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.