Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
module not found error
#1
I have never used pygame, but I want to try out a little game I am making, so I installed pygame in my VENV called GPE.

Quote:(GPE) peterr@peterr-Modern-15-B7M:~/PVE$ pip install pygame
Requirement already satisfied: pygame in ./GPE/lib/python3.12/site-packages (2.6.1)
(GPE) peterr@peterr-Modern-15-B7M:~/PVE$

Try to run the game, says no module pygame:

Quote:(GPE) peterr@peterr-Modern-15-B7M:~/PVE$ games/versuch1.py
Traceback (most recent call last):
File "/home/peterr/PVE/games/versuch1.py", line 3, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
(GPE) peterr@peterr-Modern-15-B7M:~/PVE$

My VENV GPE is active

I think maybe my shebang is wrong? I never installed pygame or anything else in the system Python, only in my VENV, GPE.

This shebang at the top of versuch1.py does not work. pygame is only installed in my VENV. (I made my little game executable, so it should run in bash.)

Quote:#! /usr/bin/python3

I tried pointing to this symlink in the VENV as the shebang:

Quote:#! /home/peterr/PVE/GPE/python3.12/bin/python3

And tried this:

Quote:#! GPE/python3.12/bin/python3

Any tips please? Is the shebang the problem??

If I start Idle, I can import pygame, no problem.

import pygame
pygame 2.6.1 (SDL 2.28.4, Python 3.12.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
pygame is installed in:

Quote:GPE/lib/python3.12/site-packages

I have not had this trouble with other packages, as far as I remember.
Reply
#2
(Jun-05-2026, 12:12 AM)Pedroski55 Wrote: Is the shebang the problem??

Yes, the shebang is the problem. Launch the program with the python command (in the activated virtual environment)
Output:
$ python games/versuch1.py
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
Some point and as mention always use python in environment so don't call stuff outside.
# Make and check that it use path in environment
om_gil_arsen@tom-down:~$ python -m venv foo_env
om_gil_arsen@tom-down:~$ cd foo_env/
om_gil_arsen@tom-down:~/foo_env$ source bin/activate

(foo_env) om_gil_arsen@tom-down:~/foo_env$ which python
/home/om_gil_arsen/foo_env/bin/python
(foo_env) om_gil_arsen@tom-down:~/foo_env$ python -c "import sys; print(sys.executable)"
/home/om_gil_arsen/foo_env/bin/python

# Install and test pygame in environment 
(foo_env) om_gil_arsen@tom-down:~/foo_env$ pip install pygame
Collecting pygame
  Downloading pygame-2.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (12 kB)
Downloading pygame-2.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (14.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.0/14.0 MB 10.1 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.6.1

(foo_env) om_gil_arsen@tom-down:~/foo_env$ python
Python 3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.6.1 (SDL 2.28.4, Python 3.12.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
Reply
#4
Thanks very much! Worked first time!

Quote:python games/versuch1.py

This is how I start the VENV in bash:

cd PVE && source GPE/bin/activate && python3 -m idlelib.idle
I was surprised to find that the VENV does not carry its own interpreter!

In my VENV GPE/python3.12/bin there are 3 symlinks: python, python3 and python3.12. The first 2 point to the 3rd symlink python3.12, and that points to the binary: /usr/bin/python3.12

In /usr/bin there is a symlink python3, which points to the binary /usr/bin/python3.12

So I am a little confused that the shebangs

#! /usr/bin/python3 and #! /usr/bin/python3.12

do not work!

Isn't that exactly what the bash command: python games/versuch1.py calls??

Thanks for your help!
Reply
#5
Hi,

I think there's still a bit of a lack of understanding what a venv does. If you read through the first couple of paragraphs on https://docs.python.org/3/library/venv.html, it should become more clear.

A venv primarily isolates the installed packages from the main / system-wide installation. Thus allows to install e.g. different versions of a package or packages conflicting the system's packages without breaking the system. This is particular useful in Linux, as most Linux distro use Python and some Python packages as an integral part of the installation and system. To ensure the venv's modules are use, always call the Python from within the venv, so either with an activated venv calling python name_of_script.py (or python3, depending on the system) or by calling Python with its full path, e.g. /home/peterr/PVE/GPE/python3.12/bin/python3 name_of_script.py. The latter is the way to go when e.g. starting on Linux a Python script within a venv with a systemd service unit.

Regards, noisefloor
Reply
#6
Thanks for your reply! Still confused!

Interestingly, I immediately find in your link, please note the bold type:

Quote:Used to contain a specific Python interpreter and software libraries and binaries which are needed to support a project (library or application). These are by default isolated from software in other virtual environments and Python interpreters and libraries installed in the operating system.

But, as far as I can tell, the interpreter used resides in /usr/bin, not in the VENV.

Like I mentioned above:

In my VENV GPE/python3.12/bin there are 3 symlinks: python, python3 and python3.12. The first 2 point to the 3rd symlink python3.12, and that points to the binary:

Quote:/usr/bin/python3.12

The same 3 symlinks appear in:

Quote:GPE/lib/python3.12/site-packages/bin

and the same is true of the symlinks: python, python3 and python3.12.

The first 2 point to the 3rd symlink python3.12, and that points to the binary:

Quote:/usr/bin/python3.12

Does your VENV have an interpreter inside the VENV?

as far as I can tell, the interpreter used resides in /usr/bin, not in the VENV.
Reply
#7
(Jun-07-2026, 10:27 AM)Pedroski55 Wrote: Does your VENV have an interpreter inside the VENV?
That's the whole point of victual environment that is should be isolated from OS system Python.
# Before active a venv it use OS system python 
tom-down:~/foo_env$ python -c "import sys; print(sys.executable)"
/usr/bin/python
# Activate 
tom-down:~/foo_env$ source bin/activate
# Then of coursed use interpreter inside venv
(foo_env) om_gil_arsen@tom-down:~/foo_env$ python -c "import sys; print(sys.executable)"
/home/foo_env/bin/python
Reply
#8
Thanks, but I am still a little confused.

Quote:That's the whole point of victual environment that is should be isolated from OS system Python.

Well something is wrong with my VENV then! I assumed the interpreter binary would lie in a folder called bin.

Quote:(GPE) peterr@peterr-Modern-15-B7M:~/PVE$ python -c "import sys; print(sys.executable)"
/home/peterr/PVE/GPE/bin/python
(GPE) peterr@peterr-Modern-15-B7M:~/PVE$

This:

Quote:/home/peterr/PVE/GPE/bin/python
is a symlink. It points to
Quote:python3
, another symlink in GPE/bin.

The symlink
Quote:python3
points to
Quote:/usr/bin/python3

There is no Python interpreter in my VENV, which is called GPE.

The activate script is also in GPE/bin.

Do you have an actual Python interpreter in your VENV foo/bin??
Reply
#9
Just to confirm the status of my folder GPE/bin I used this command in bash:

Quote:ls -al GPE/bin

In part it shows:

Quote:lrwxrwxrwx 1 peterr peterr 7 Jun 2 2025 python -> python3
lrwxrwxrwx 1 peterr peterr 16 Jun 2 2025 python3 -> /usr/bin/python3
lrwxrwxrwx 1 peterr peterr 7 Jun 2 2025 python3.12 -> python3
Reply
#10
(Jun-08-2026, 07:06 AM)Pedroski55 Wrote: Well something is wrong with my VENV then! I assumed the interpreter binary would lie in a folder called bin.
Yes,it look ok.
Do you not have python,python3 in bin folder?
If i look folder in my venv bin folder.
tom-down:~/foo_env/bin$ ls
Activate.ps1  activate  activate.csh  activate.fish  pip  pip3  pip3.12  python  python3  python3.1
This is when i make environment with build in venv
python -m venv foo_env
cd foo_env/
source bin/activate
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Upgraded Python: Module no longer found - for Linux Curbie 8 3,661 Mar-05-2025, 06:01 PM
Last Post: Curbie
Question [SOLVED] Upgraded Python: Module no longer found Winfried 1 2,893 Jan-01-2025, 02:43 PM
Last Post: Larz60+
  Module not found error even though installed NZGeorge 1 8,179 Jul-10-2024, 09:08 AM
Last Post: Larz60+
  file open "file not found error" shanoger 8 17,397 Dec-14-2023, 08:03 AM
Last Post: shanoger
  pyside6 module not found ForeverNoob 4 12,749 Aug-18-2023, 04:36 PM
Last Post: snippsat
  Module Not Found Error bitoded 4 3,491 Jan-01-2023, 09:08 AM
Last Post: bitoded
  pdfminer package: module isn't found Pavel_47 25 23,613 Sep-18-2022, 08:40 PM
Last Post: Larz60+
  Module not found question sighhhh12 0 2,612 Sep-09-2022, 05:43 AM
Last Post: sighhhh12
  [SOLVED] Tkinter module not found Milan 7 60,602 Aug-05-2022, 09:45 PM
Last Post: woooee
  No module found when I run a main.py tomtom 2 3,897 Jul-20-2022, 09:24 AM
Last Post: tomtom

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020