0

Similar to this question, I have problems importing my own modules and get an ImportError: No module named .... For example, I have a module at myfolder/mymodule.py that I try to load with from myfolder import mymodule.

The difference to the other question is that it was working fine before and the problem only occurs on one machine (it works on two other machines). Also I think I know what might have caused the problem: I ran sudo pip install numpy to install NumPy. Now, I read that you should never use sudo with pip install, but it's too late.

Is it possible that sudo pip install broke something here? If so, how can I fix it?

So far, I didn't mess with PYTHONPATH as suggested by the top answer because I also read that you shouldn't have to touch it when using pip and I don't want to further break the system.

Just to clarify; numpy installed correctly, works and is listed when running pip freeze. The problem is really with importing my own module. I don't have a setup.py yet. And again, it worked before - so why would I suddenly need to set a variable or path?

stefanbschneider
  • 5,460
  • 8
  • 50
  • 88
  • 1
    what does `pip freeze` say? – Joost Apr 23 '18 at 17:40
  • Instead of `pip install` try `pip3 install` – Qwerty Apr 23 '18 at 17:52
  • `pip freeze` shows all installed packages correctly, including `numpy`. It also gives me a hint to update pip with `pip install --upgrade pip`, which gives me a `Permission denied` when trying to run it. I guess I messed that up when installing with `sudo`? @Qwerty I updated my question to clarify what I want. There's nothing left to install. `numpy` is also already installed with `pip3`. – stefanbschneider Apr 23 '18 at 19:38

2 Answers2

0

Did you make sure the path to your Python/ Anaconda installation is added to your user path environment variable? I had a similar problem and fixed it once I did that

0

I'm still not sure what suddenly caused the problem (if it was really caused by using sudo pip install).

Anyway, I fixed it by properly packaging my code with a setup.py and then installing it with sudo python3 setup.py develop. Didn't work without sudo.

stefanbschneider
  • 5,460
  • 8
  • 50
  • 88