osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using __init__.py


On Wed, 6 Sep 2017 07:30 pm, Kryptxy wrote:

> I am working on a (cross-platform) project. On linux system, the imprts work
> fine, but in windows I get imort error (I have no idea why. I tried searching
> everywhere, but couldn't get it to work). Anyways, the issue seem to be
> resolved by adding project directory to sys.path().
> 
> I wanted to know that can I use __init__.py file for adding a project
> directory to sys.path (sys.path.insert(0, directory))?

That is the wrong way to fix this problem. It might work, for a little while,
but then something will change, or you will do something just a tiny bit
different, and it will break again.

The first step is to debug why you are getting the import error. You cannot fix
a problem until you know what it is: what you fix by accident will break by
accident.

Start by telling us the full path to your project directory, and the full
contents of sys.path.

Do not try to retype them from memory. Accuracy is essential: copy and paste the
paths so that they are accurate.


Thank you.



-- 
Steve
?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure
enough, things got worse.