Skip to main content
added 157 characters in body
Source Link
Joran Beasley
  • 114.4k
  • 13
  • 167
  • 187

the sys.path tells python where to look for imports

add

import sys
sys.path.insert(0,".")

to the top of your main python script this will ensure local packages are imported BEFORE builtin packages (although tbh I think this happens automagically)

if you really want to import only packages in your folder do

import sys
sys.path = ["."]

however I do not reccommendnot recommend this at all as it will probably breakprobably break lots of your stuff ...

most IDE's (eclipse/pycharm/etc) provide mechanisms to set up the environment a project uses including its paths

really the best option is not to name packages the same as builtin packages or 3rd party modules that are installed on your system

also the best option is to distribute it via a correctly bundled package, this should more than suffice

the sys.path tells python where to look for imports

add

import sys
sys.path.insert(0,".")

to the top of your main python script this will ensure local packages are imported BEFORE builtin packages

if you really want to import only packages in your folder do

import sys
sys.path = ["."]

however I do not reccommend this at all as it will probably break lots of your stuff ...

most IDE's (eclipse/pycharm/etc) provide mechanisms to set up the environment a project uses including its paths

really the best option is not to name packages the same as builtin packages or 3rd party modules that are installed on your system

the sys.path tells python where to look for imports

add

import sys
sys.path.insert(0,".")

to the top of your main python script this will ensure local packages are imported BEFORE builtin packages (although tbh I think this happens automagically)

if you really want to import only packages in your folder do

import sys
sys.path = ["."]

however I do not recommend this at all as it will probably break lots of your stuff ...

most IDE's (eclipse/pycharm/etc) provide mechanisms to set up the environment a project uses including its paths

really the best option is not to name packages the same as builtin packages or 3rd party modules that are installed on your system

also the best option is to distribute it via a correctly bundled package, this should more than suffice

Source Link
Joran Beasley
  • 114.4k
  • 13
  • 167
  • 187

the sys.path tells python where to look for imports

add

import sys
sys.path.insert(0,".")

to the top of your main python script this will ensure local packages are imported BEFORE builtin packages

if you really want to import only packages in your folder do

import sys
sys.path = ["."]

however I do not reccommend this at all as it will probably break lots of your stuff ...

most IDE's (eclipse/pycharm/etc) provide mechanisms to set up the environment a project uses including its paths

really the best option is not to name packages the same as builtin packages or 3rd party modules that are installed on your system