Issue
I have been using an open source package installed via pip and running inside a Jupyter Notebook IPython environment.
I needed to modify the source of the package so I cloned the repo locally and made the changes and imported the local package instead of the installed package with no problem.
The problem I have is that inside the project source it imports its own package which is importing the installed package instead of the source project and causes a conflict in the code in a few cases.
Say the package name is PackageA
, originally installed via pip install PackageA
. I now have the source code for Package A
in libs/
directory underneath my project directory. projectDir/libs/PackageA
. I am importing the project via from libs.PackageA import PackageA as pa
, however in the source code (in almost every file) it has import PackageA as pa
.
I can go through the source and change every instance of import PackageA as pa
with from .. import PackageA as pa
but this occurs in probably over 100 files as some files have multiple import statements and its also very untidy as some files are in sub directories requiring from .... import PackageA as pa
.
Is there a way to redirect the import to use the local version instead of the installed version (I have already uninstalled the pip installed version).
I am fairly new to python (not to software development) so is there a best practice for this type of setup as I'm sure its fairly common.
Solution
you could add sys.path.append("../libs")
before project start.
Answered By - Charles Cao
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.