Reputation: 177
I recently installed Ubuntu 18.04.4 which came with Python 3.7.6 installed. I installed Atom v1.45, which comes with Python 2.7 automatically.
When running a Python script from the terminal, it raises ModuleNotFoundError
. I figured that if I ran the script from the terminal with python3.7 file.py
instead of python file.py
there is no problem, though it is slightly annoying to do that all the time.
I uninstalled python2.7 but then I could not use Atom.
How can solve this problem?
Upvotes: 0
Views: 71
Reputation: 582
I faced a very similar problem. Some of the tips from my end are:
I recommend using a virtual environment when running scripts from the command-line. This helps resolve all module dependencies for the script in general and especially when dealing with multiple Python versions.
$ virtualenv -p /usr/bin/python3 ./venv
$ source ./venv/bin/activate
$ ./venv/bin/python foo.py
Typically, the above steps, are either in my Makefile or in a helper script.
python
instead of python3.7
, you can create a symlink for python
to point to python3
in the /usr/bin
directory. Also, I recommend switching to python3
completely since support for python2.7
has officially stopped.
Upvotes: 4