简体   繁体   中英

How to make python import an identically named module from the local directory instead site-packages?

I'm a bit confused on how python separates between modules installed in site-packages and modules in the local directory if they have identical names and what's the best way to make python import the module from the local directory instead of the installed one.

Basically I have a command line app and I'm using this to install it with setup.py

setup(
      name='app',
      version='0.5.2',
      packages=find_packages(),
      entry_points={
          'console_scripts': [
              'katana = app.main:main'
          ]
      }
)

The problem I having is that when I'm run main.py from my source folder and do:

import app.script_A

instead of src/scriptA.py (same folder as main.py) it imports the installed module from

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/app-0.5.2-py3.5.egg!/app/scriptA.py

So what is the proper way to solve this, if I want to still be able to install the module system wide with setuptools, but when running the main.py from the source folder manually I want it to import all the modules from that folder instead of Library?

if scriptA.py is in the same directory of main.py can't you just import .scriptA ?

The . is a shortcut that tells python to search in current package before rest of the PYTHONPATH

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