0

I have searched far and wide, and have followed just about everything... I cannot figure out why this keeps happening to my Python package I've created. It's not a simple "install dependency and you're good" as it's my own project I am attempting to create.

Here's my file structure:

-jarvis-discord
--jarvis_discord_bot
---__init__.py
---jarvis.py
---config.py
---cogs
----__init__.py
----all the cogs are here

The error given:

++ PWD
line 3: PWD: command not found
export PYTHONPATH=
PYTHONPATH=
python3 jarvis_discord_bot/jarvis.py
Traceback (most recent call last):
  File "/buddy/jarvis-discord/jarvis_discord_bot/jarvis.py", line 40, in <module>
    from jarvis_discord_bot.cogs import (
ModuleNotFoundError: No module named 'jarvis_discord_bot'

I've tried creating a pipenv as well and have had no luck either. Same error as above. There's something wrong with how I'm setting up my Python environment... granted I'm also a newbie.

The weird thing, to top this all off, is that it runs locally on my own machine just fine. So I am at a complete and utter loss for what to do and could use some help and direction on where to go from here.

Thanks!

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Chan
  • 1
  • 3

2 Answers2

1

If you are using relative file paths, you have to use from .cogs import ( because it jarvis.py can't see jarvis_discord_bot from one level below. The . in front of cogs means that it is one level up.

Timothy Chen
  • 431
  • 3
  • 8
-1

Figured out what was the issue!

In my run file, I had to set PYTHONPATH from PWD to the actual folder of the project. Good luck to anyone reading this in the future!

Chan
  • 1
  • 3
  • 2
    You almost never need to modify `PYTHONPATH`, this is a common misconception. Your issue probably lies in how you call your code you need the `python -m package.module` notation. See: https://sinoroc.github.io/kb/python/python_imports.html – sinoroc Dec 30 '20 at 09:03
  • 1
    I would also recommend reading this: https://stackoverflow.com/a/50193944 – sinoroc Dec 30 '20 at 09:09