-3

I'm trying to run a scrip that uses openpyxl. I have the module installed correctly and am only getting this error when trying to run the script by clicking the file/ running it from the command line. It does work when I run it from the command line as "python enter-info.py", but not when I run it by itself.

Error when trying to run script

ForceBru
  • 43,482
  • 10
  • 63
  • 98
Mike
  • 1
  • That suggests you may have a different version of Python associated with file type `.py` or that you have a *shebang* on the first line pointing to a different version of Python. – Booboo Dec 08 '19 at 17:27

3 Answers3

1

If you want to run a .py file as a stand alone, you should use the shebang line. Also, you should use the compatible python version

0

Do you have multiple versions of Python installed on your system? It may be running with a different version of Python when you run it that way. For a quick fix, try running pip install openpyxl or pip3 install openpyxl --user.

In times of desperation, the above have worked for me; however, I recommend using a virtual environment in cases like these to prevent this issue in the future. Otherwise, this solution looks promising as well although I have never tried it myself.

Good luck!

0

try

python3 yourfile.py  # for python3 if you have python2 installed
python yourfile.py # if you have only one python installed
Igor Alex
  • 841
  • 2
  • 10
  • 21
  • This works, but it's not the problem. I'm trying to run the script from the icon, but that's when it throws the error. Running python .py works, running just .py does not. – Mike Dec 08 '19 at 18:58
  • What OS do you use? – Igor Alex Dec 08 '19 at 19:16