2

I have this error when running the script from terminal but works from PyCharm

C:\Users\Username\PycharmProjects\Space Invaders>python main.py
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import pygame
ModuleNotFoundError: No module named 'pygame'

This is how my file directory looks: https://i.sstatic.net/s9qB5.png

I am using python 3.8 and pygame 2.0.1

Should I have to install pygame globally for me to run the script from command line? I have the package installed in a virtual environment.

1 Answer 1

1

You're trying to execute the script with global python which doesn't have the pygame package installed. So, you have to activate the virtual environment first. To do this, go to venv/Scripts/ and there will be an "activate" file that you need to execute. Once you have done this you can run your script and it should work.

More info on: https://docs.python.org/3/tutorial/venv.html

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

Comments

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.