Venv module in pip list but not recoginsed when script running

Tried for a few hours all options - I can’t figure out why the script cant see the pyx2cscope module when running.

A)

Error runing python script

(.venv) PS C:\Users\A14451\PyX2C312> py motor_gui.py
Traceback (most recent call last):
File “C:\Users\A14451\PyX2C312\motor_gui.py”, line 18, in
from pyx2cscope.x2cscope import X2CScope
ModuleNotFoundError: No module named ‘pyx2cscope’

B)PIP LIST

(.venv) PS C:\Users\A14451\PyX2C312> pip list
Package Version


bidict 0.23.1
blinker 1.9.0
click 8.3.1
colorama 0.4.6
contourpy 1.3.3
cycler 0.12.1
Flask 3.1.3
fonttools 4.62.0
h11 0.16.0
itsdangerous 2.2.0
Jinja2 3.1.6
kiwisolver 1.5.0
MarkupSafe 3.0.3
matplotlib 3.10.8
mchplnet 0.4.1
numpy 1.26.4
packaging 26.0
pillow 12.1.1
pip 26.0.1
pyelftools 0.31
pyparsing 3.3.2
PyQt5 5.15.11
PyQt5-Qt5 5.15.2
PyQt5_sip 12.18.0
pyqtgraph 0.13.7
pyserial 3.5
python-dateutil 2.9.0.post0
python-engineio 4.13.1
python-socketio 5.16.1
pyx2cscope 0.6.1
PyYAML 6.0.3
simple-websocket 1.1.0
six 1.17.0
Werkzeug 3.1.6
wsproto 1.3.2
(.venv) PS C:\Users\A14451\PyX2C312>

C). Python version

(.venv) PS C:\Users\A14451\PyX2C312> py -V
Python 3.12.10
(.venv) PS C:\Users\A14451\PyX2C312>

D. First part of the script just the start

py motor_gui.py

#!/usr/bin/env python3

import pathlib

import threading

import time

import tkinter as tk

from tkinter import filedialog, messagebox, ttk

import serial.tools.list_ports

USE_SCOPE = True

if USE_SCOPE:

    from pyx2cscope.x2cscope import X2CScope   # this is line 18

I don’t think a venv’s .\scripts contains a py.exe. Just various python.exes

Try launching the script ith python instead of py.

executed IDLE and it found the module when I imported it

import pyx2cscope *no error

YES!!
Working!!! it was the Win11 App Alias for python programs (many) I had to turn off

Then use python rather than py ??? Why does that work?

I assume you activated tne venv, which will put tne venv’s python.exe on your PATH.

Because you need to run the python.exe that is inside the venv.
Not py.exe that is outside the venv.

Yes… the Windows Aliases kept wanting me to install python from MS store when executing python.exe

You can disable/remove the Windows python alias.

Yep. Removing all win10 App Alice’s for python fixed ii

Removed thank Barry

I think Windows Aliases have priority over venv and the Eviroment paths

In the bin directory/folder of the Python VENV, you have a python executable there.
bin/python <SCRIPT-NAME.py>, will execute the Python script with the modules from the Python VENV. Alternatively, you can also change the Shabang line with the correct path to your Python binary. E.G with relative path:

python3 -m venv test
test/bin/python script.py

Or in script.py the first line should be:

#!test/bin/python

Directly executing the script.py without a Python binary call should work as well (script.py)!
Hopefully, you can also do this on Windows with backslashes instead of forward slashes! ;^)