0

I am having so much trouble with imports and I never know how to solve them. The folders of the project are arranged as follows

project:
   distributed_computing:
       agent_server.py
   kinematics:
       inverse_kinematics.py

I am trying to import inverse_kinematics into agent_server.py.

The code used for that is :

import os
import sys
sys.path.append(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'kinematics'))

from kinematics import inverse_kinematics

I get the error ModuleNotFoundError: No module named 'kinematics'.

Following this tutorial I also tried to modify PYTHONPATH by adding the whole path C:\Users\TheCh\.......\project but it didn't change anything.

JooJoo
  • 11
  • 1
  • Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – Squarish Jun 04 '23 at 16:29

1 Answers1

0

The script should not worry about modifying sys.path. It should assume that it will be executed in an environment where the top-level package kinematics is located in a directory in sys.path. That's what

PYTHONPATH=/path/to/project python /path/to/agent_server.py

does, no matter what the current working directory is.

chepner
  • 497,756
  • 71
  • 530
  • 681