Fatemeh Hosseini
Fatemeh Hosseini

Reputation: 91

/usr/bin/python3: No module named pytest

I use python3 -m pytest to run my tests. This was working when python3 was pointing to python3.6. I installed python3.7, made python3.7 as my default python3 with these commands:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
sudo update-alternatives --config python3 

and installed all the required packages again for python3.7. But now I cannot run my tests anymore. Because it says: /usr/bin/python3: No module named pytest. I'm not using virtual env and the problem is not about a specific module, because it cannot find other modules either. It should be related to python paths. I don't know what to change after switching between python3 versions so it can easily find the required modules in /home/ubuntu/.local/lib/python3.x/site-packages/.

I switched back to python3.6 and getting ModuleNotFoundError: No module named 'jsonpath_ng' now, which was working before switching to python3.7. This is the output of python3 -m site:

sys.path = [
    '/home/ubuntu',
    '/usr/lib/python36.zip',
    '/usr/lib/python3.6',
    '/usr/lib/python3.6/lib-dynload',
    '/home/ubuntu/.local/lib/python3.6/site-packages',
    '/usr/local/lib/python3.6/dist-packages',
    '/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/ubuntu/.local' (exists)
USER_SITE: '/home/ubuntu/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True

Upvotes: 5

Views: 12007

Answers (1)

Fatemeh Hosseini
Fatemeh Hosseini

Reputation: 91

Thank you to @hoefling, I found the problem by running python3 -m site. I was running tests with my jenkins user and not the root, while I was installing everything for the root user. So USER_SITE didn't actually exist for jenkins user. I installed everything again for the jenkins user and now it can find the modules when I use python3 -m.

Upvotes: 3

Related Questions