I created a virtual environment myenv1
on machine #1.
I installed some packages in this virtual environment.
pip3 freeze
shows me this list of packages:
cffi==1.15.1
chardet==5.0.0
click==8.0.4
cryptography==39.0.0
dataclasses==0.8
distlib==0.3.6
dnspython==2.2.1
filelock==3.4.1
Flask==2.0.3
future==0.18.2
impacket==0.10.0
importlib-metadata==4.8.3
importlib-resources==5.4.0
itsdangerous==2.0.1
Jinja2==3.0.3
ldap3==2.9.1
ldapdomaindump==0.9.4
MarkupSafe==2.0.1
natsort==8.2.0
platformdirs==2.4.0
pyasn1==0.4.8
pycparser==2.21
pycryptodomex==3.16.0
pyOpenSSL==23.0.0
six==1.16.0
typing_extensions==4.1.1
virtualenv==20.17.1
Werkzeug==2.0.3
zipp==3.6.0
I archived the folder myenv1
and copied it to machine #2 (which is identical to machine #1).
On machine #2 I activated myenv1
. pip3 freeze
shows the same list of packages. So looks like the transfer passed successfully.
But when I run some code that requires these packages, I see ModuleNotFoundError: No module named 'impacket
, so Python does not see the installed packages.
When I check sys.path
I see the folder of my virtual environment myenv1
:
python3 -c "import sys; print('\n'.join(sys.path))"
/usr/lib64/python36.zip
/usr/lib64/python3.6
/usr/lib64/python3.6/lib-dynload
/opt/allot/igor_test/myenv1/lib64/python3.6/site-packages
/opt/allot/igor_test/myenv1/lib/python3.6/site-packages
Why doesn't the virtual environment see its own packages? How can I make these packages visible?
UPD
I found the issue.
This is the script that I run:
#!/usr/bin/python3
import argparse
import re
import sys
import configparser
import io
from impacket.dcerpc.v5.rpcrt import RPC_C_AUTHN_LEVEL_PKT_INTEGRITY, RPC_C_AUTHN_GSS_NEGOTIATE
from natsort import natsorted, ns
from impacket.dcerpc.v5.dtypes import NULL
from impacket.dcerpc.v5.dcom import wmi
from impacket.dcerpc.v5.dcomrt import DCOMConnection
... //and all the code further
This script addresses to #!/usr/bin/python3
which is a global Python. And global python does not see packages fron virtual environment.
I replaced this line with python from my virtual environment:
#!/path/to/my/virt_env/myenv1/bin/python3
and everythind started working.