4

I've added a local directory to my system path. When I import it, it's fine but when I do

import local_repo 
print(local_repo.__file__) 

it returns None.

How do I get it to return the path...

P.S. When I try this with other modules works fine - returns the path - for example

import pathlib 
print(pathlib.__file__)

>>>> "C:\Python38\lib\pathlib.py"
Neuron
  • 5,141
  • 5
  • 38
  • 59
Kurtis Pykes
  • 301
  • 3
  • 14
  • Maybe you can find some clues in [what does the __file__ variable mean/do?](https://stackoverflow.com/q/9271464/5987). – Mark Ransom Oct 09 '20 at 15:21
  • 1
    Is there a __init__.py? – Shlomo Fel Oct 09 '20 at 15:27
  • No, but I thought that python 3.3 and up no longer require an __init__.py. I tried it and that was the issue (it is working now). If you put that as a answer I can mark it as the solution @ShlomoFel – Kurtis Pykes Oct 09 '20 at 17:07

2 Answers2

8

__init__.py file should solve it.

Neuron
  • 5,141
  • 5
  • 38
  • 59
Shlomo Fel
  • 196
  • 1
  • 1
  • 8
1

Possibly not an answer to your specific situation, but I had issues with code in a parent package. The code was preventing the child module from initializing properly and the errors were cryptic and pointed at other modules. If you run into this issue, you may want to check other parent and imported modules.

Eric Fossum
  • 2,395
  • 4
  • 26
  • 50