-2

I know there're tons of questions about relative import in python, but none of them work with my script.

Here's my project directory tree:

project\
    Enums\
        Candle.py
    Trader\
        Trader.py

As I run this command:

python Trader\Trader.py

And here's how I import a class from Enums in Trader.py:

from Enums.CandleColor import CandleColor

I get this error:

Traceback (most recent call last):
    File "C:\Users\user\Desktop\Proj\Test\Trader\Trader.py", line 6, in <module>
        from Strategy import Strategy
    File "C:\Users\user\Desktop\Proj\Test\Trader\Strategy.py", line 2, in <module>
        from Enums.CandleColor import CandleColor

I tried different ways of fixing this including adding the parent directory to sys.path, using .. while importing, etc. but none of them didn't work.

As I run this project in PyCharm, it works just fine but from a command prompt, I get these errors.

  • Show the full traceback of the error as properly formatted text in the question. – Michael Butscher May 11 '22 at 14:24
  • Maybe you could look up your answer in this questions [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder#:~:text=By%20default%2C%20you%20can%27t.%20When%20importing%20a%20file%2C,can%20add%20to%20the%20Python%20path%20at%20runtime%3A) – theDreamer911 May 11 '22 at 14:24
  • how do you imported 'Enums' in Trader.py ? – Med_siraj May 11 '22 at 14:25
  • 2
    You have skipped `__init__.py` everywhere. – aneroid May 11 '22 at 14:42

0 Answers0