0

I found that when I run my scripts from environment - everything is OK.

But, when I try to run them from bash - I receive different errors with import modules. (ModuleNotFoundError, ImportError)

I didn't set the environment at all, so, please, tell me, what I should configure to succeed with it.

I use python 3.7

Received the next error:

Traceback (most recent call last): 
File "main.py", line 1, in <module> from package_3.file3 import * 
ModuleNotFoundError: No module named 'package_3'

The structure is:

package_1
   file1.py
package_2
   file2.py
package_3
   file3.py
package_4
   file4.py
5
  • 1
    Could you provide some more details? What version of python are you using (in what you refer to as 'the environment')? What errors are you getting? also, run 'which python' in the shell, and provide the results. Commented May 25, 2020 at 7:26
  • 1
    and when you run 'which python' - what do you get? Commented May 25, 2020 at 7:30
  • /usr/bin/python Commented May 25, 2020 at 7:31
  • To help, one really needs to see exactly what you're seeing. What command do you run when you get this error? What's the current directory? What's the exact file structure? You're getting a message about package_suits, but your file structure doesn't contain any such file or directory. Commented May 25, 2020 at 9:30
  • I change directory to mine and run command: python3 package_4/file4.py Commented May 25, 2020 at 9:33

1 Answer 1

1

What happens is, probably, that your working environment is python3, and when you run things in the shell, it's using python2. To solve it, run your script with python3 in the shell, as in:

python3 my_script.py
Sign up to request clarification or add additional context in comments.

17 Comments

what do you see when you run "python3 --version " and "which -a python3" ?
And what version do you use in the environment where it does work? (what do mean by 'environment', by the way)?
When you run this in your environment, what do you get: import sys; print(sys.version_info)
and another thing to check - run "print(sys.argv[0])" in your environment.
so you're using PyCharm. Which Python interpreter is configured there (see this page: jetbrains.com/help/pycharm/configuring-python-interpreter.html)?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.