.tox/py36/bin/python: No module named pip
OS: EC2 (Amazon Linux)
Pip list:
- pip (9.0.3)
- pluggy (0.7.1)
- py (1.6.0)
- setuptools (36.2.7)
- six (1.11.0)
- toml (0.9.6)
- tox (3.4.0)
- virtualenv (16.0.0)
Here's the tox.ini:
[tox] envlist = py36
[testenv] deps = pytest pytest-mock commands = pytest
I'm having a problem when running tox with python3.6 but works fine with python 2.7. I get the following error when running tox:
GLOB sdist-make: /TestRepo/project/setup.py py36 create: /TestRepo/project/.tox/py36 py36 installdeps: pytest, pytest-mock ERROR: invocation failed (exit code 1), logfile: /TestRepo/project/.tox/py36/log/py36-1.log ERROR: actionid: py36 msg: getenv cmdargs: '/TestRepo/project/.tox/py36/bin/python -m pip install pytest pytest-mock'
/TestRepo/project/.tox/py36/bin/python: No module named pip
ERROR: could not install deps [pytest, pytest-mock]; v = InvocationError('/TestRepo/project/.tox/py36/bin/python -m pip install pytest pytest-mock (see /TestRepo/project/.tox/py36/log/py36-1.log)', 1)
Any help with be appreciated. Thanks in advance!
Hi @BenRbtz, this means that your py36 interpreter has no pip installed.
For Amazon Linux, pip is not installed, it will be neccessary:
$ curl -O https://bootstrap.pypa.io/get-pip.py and $ python3 get-pip.py --user
-- https://gist.github.com/niranjv/f80fc1f488afc49845e2ff3d5df7f83b#gistcomment-2570550
(or use any other means you see fit to install pip)
Thanks for the reply and suggestion!
I tried what you recommend but it still yields the same error. I even ran the script to rebuild python then the get-pip script but to no avail.
@BenRbtz can you provide the content for tox -e py36 -vvvv, thanks 👍
Sure thing :)
tox -e py36 -vvvv:
removing /usr/local/TestRepo/project/.tox/log using tox.ini: /usr/local/TestRepo/project/tox.ini using tox-3.4.0 from /usr/lib/python3.6/dist-packages/tox/init.py GLOB start: packaging GLOB sdist-make: /usr/local/TestRepo/project/setup.py removing /usr/local/TestRepo/project/.tox/dist /usr/local/TestRepo/project$ /usr/bin/python3.6 /usr/local/TestRepo/project/setup.py sdist --formats=zip --dist-dir /usr/local/TestRepo/project/.tox/dist >/usr/local/TestRepo/project/.tox/log/tox-0.log GLOB finish: packaging after 0.33 seconds copying new sdistfile to '/root/.tox/distshare/testName-0.0.0.zip' py36 start: getenv /usr/local/TestRepo/project/.tox/py36 py36 cannot reuse: no previous config /usr/local/TestRepo/project/.tox/py36/.tox-config1 py36 create: /usr/local/TestRepo/project/.tox/py36 removing /usr/local/TestRepo/project/.tox/py36 setting PATH=/usr/local/TestRepo/project/.tox/py36/bin:/opt/phpbrew/php/php-7.2.1/bin:/root/.phpbrew/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin /usr/local/TestRepo/project/.tox$ /usr/bin/python3.6 -m virtualenv --python /usr/bin/python3.6 py36 >/usr/local/TestRepo/project/.tox/py36/log/py36-0.log py36 installdeps: pytest, pytest-mock setting PATH=/usr/local/TestRepo/project/.tox/py36/bin:/opt/phpbrew/php/php-7.2.1/bin:/root/.phpbrew/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin /usr/local/TestRepo/project$ /usr/local/TestRepo/project/.tox/py36/bin/python -m pip install pytest pytest-mock /usr/local/TestRepo/project/.tox/py36/bin/python: No module named pip ERROR: could not install deps [pytest, pytest-mock]; v = InvocationError("'/usr/local/TestRepo/project/.tox/py36/bin/python -m pip install pytest pytest-mock'", 1) py36 finish: getenv after 2.88 seconds __________________________________________________________________________________________________________________ summary __________________________________________________________________________________________________________________ ERROR: py36: could not install deps [pytest, pytest-mock]; v = InvocationError("'/usr/local/TestRepo/project/.tox/py36/bin/python -m pip install pytest pytest-mock'", 1)
seems the problem is that the virtual environment we create does not have pip inside it. virtualenv should ensure this, /usr/bin/python3.6 -m virtualenv --python /usr/bin/python3.6 something goes wrong here. Can you try to run only that command perhaps with some verbose flags and see what happens? Also do a pip freeze as /usr/bin/python3.6 -m pip and the same with the created venv (perhaps also after tox fails).
/usr/bin/python3.6 -m pip freeze
pluggy==0.7.1 py==1.6.0 six==1.11.0 toml==0.9.6 tox==3.4.0 virtualenv==16.0.0 You are using pip version 9.0.1, however version 18.0 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
/usr/bin/python3.6 -m virtualenv -v --python /usr/bin/python3.6 .
Already using interpreter /usr/bin/python3.6 Using base prefix '/usr' Creating /usr/local/TestRepo/test/lib/python3.6 Symlinking Python bootstrap modules Symlinking /usr/local/TestRepo/test/lib/python3.6/config-3.6m-x86_64-linux-gnu Symlinking /usr/local/TestRepo/test/lib/python3.6/lib-dynload Symlinking /usr/local/TestRepo/test/lib64/python3.6/os.py Ignoring built-in bootstrap module: posix Symlinking /usr/local/TestRepo/test/lib64/python3.6/posixpath.py Cannot import bootstrap module: nt Symlinking /usr/local/TestRepo/test/lib64/python3.6/ntpath.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/genericpath.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/fnmatch.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/locale.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/encodings Symlinking /usr/local/TestRepo/test/lib64/python3.6/codecs.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/stat.py Cannot import bootstrap module: UserDict Cannot import bootstrap module: copy_reg Symlinking /usr/local/TestRepo/test/lib64/python3.6/types.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/re.py Cannot import bootstrap module: sre Symlinking /usr/local/TestRepo/test/lib64/python3.6/sre_parse.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/sre_constants.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/sre_compile.py Cannot import bootstrap module: _abcoll Symlinking /usr/local/TestRepo/test/lib64/python3.6/warnings.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/linecache.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/abc.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/io.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/_weakrefset.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/copyreg.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/tempfile.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/random.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/future.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/collections Symlinking /usr/local/TestRepo/test/lib64/python3.6/keyword.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/tarfile.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/shutil.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/struct.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/copy.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/tokenize.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/token.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/functools.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/heapq.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/bisect.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/weakref.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/reprlib.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/base64.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/_dummy_thread.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/hashlib.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/hmac.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/imp.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/importlib Symlinking /usr/local/TestRepo/test/lib64/python3.6/rlcompleter.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/operator.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/_collections_abc.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/_bootlocale.py Symlinking /usr/local/TestRepo/test/lib64/python3.6/enum.py Creating /usr/local/TestRepo/test/lib/python3.6/site-packages Writing /usr/local/TestRepo/test/lib64/python3.6/site.py Writing /usr/local/TestRepo/test/lib64/python3.6/orig-prefix.txt Writing /usr/local/TestRepo/test/lib64/python3.6/no-global-site-packages.txt Creating parent directories for /usr/local/TestRepo/test/include Symlinking /usr/local/TestRepo/test/include/python3.6m Creating /usr/local/TestRepo/test/bin New python executable in /usr/local/TestRepo/test/bin/python3.6 Changed mode of /usr/local/TestRepo/test/bin/python3.6 to 0o755 Also creating executable in /usr/local/TestRepo/test/bin/python Changed mode of /usr/local/TestRepo/test/bin/python to 0o755 Testing executable with /usr/local/TestRepo/test/bin/python3.6 -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))" Got sys.prefix result: '/usr/local/TestRepo/test' Symlinking /usr/local/TestRepo/test/local/include Symlinking /usr/local/TestRepo/test/local/lib Symlinking /usr/local/TestRepo/test/local/lib64 Symlinking /usr/local/TestRepo/test/local/bin Creating /usr/local/TestRepo/test/lib64/python3.6/distutils Writing /usr/local/TestRepo/test/lib64/python3.6/distutils/init.py Writing /usr/local/TestRepo/test/lib64/python3.6/distutils/distutils.cfg Installing setuptools, pip, wheel... Looking in links: /usr/lib/python3.6/dist-packages, /usr/lib/python3.6/dist-packages/virtualenv_support, /usr/lib/python3.6/dist-packages/virtualenv_support Collecting setuptools Using cached https://files.pythonhosted.org/packages/96/06/c8ee69628191285ddddffb277bd5abdf769166e7a14b867c2a172f0175b1/setuptools-40.4.3-py2.py3-none-any.whl Collecting pip Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl Collecting wheel Installing collected packages: setuptools, pip, wheel Successfully installed pip-18.0 setuptools-40.4.3 wheel-0.31.1 ...Installing setuptools, pip, wheel...done. Writing /usr/local/TestRepo/test/bin/activate Writing /usr/local/TestRepo/test/bin/activate.fish Writing /usr/local/TestRepo/test/bin/activate.csh Writing /usr/local/TestRepo/test/bin/activate_this.py Writing /usr/local/TestRepo/test/bin/python-config Changed mode of /usr/local/TestRepo/test/bin/python-config to 0o755
Sorry, forgot to add this in too. I ran this with the generated bin and it worked fine:
bin/python3.6 -m pip install pytest pytest-mock
So you're saying it works if you use the command directly, but fails from within tox. 🤔 ?
I just double check and yes, it's as you said :(
Can you check output of pip list --user and pip list --local of the pip command respectively?
pip list --local
Package Version
pip 18.0 pluggy 0.7.1 py 1.6.0 setuptools 40.4.3 six 1.11.0 toml 0.9.6 tox 3.4.0 virtualenv 16.0.0 wheel 0.31.1
pip list --user
Package Version
pip 18.0 wheel 0.31.1
@BenRbtz @gaborbernat I've been having the exact same issues running tox on EC2 Amazon Linux, using python36 installed via yum.
The only thing that worked was uninstalling python36 and instead installing pyenv and managing the python installation from there.
Hi @jsfehler, I just tried to reproduce this with a fresh ec2 instance. If I say yum install python3 it installs python 3.7 and I can't find a way to install 3.6 via yum. Could you explain how you did that?
@obestwalter I believe it was just sudo yum install python36
edit: https://aws.amazon.com/amazon-linux-ami/2017.09-release-notes/ provides python36 instructions
Tried that - no luck. Seems like pyenv seems a good way to go to get Python36 on an Amazon Linux.
As I can't reproduce this. I'll close this now as a highly specific corner case that is not even reproducible anymore. I tried playing this through with the Python 3.7 that now seems to ship with current versions of Amazon Linux and all is working as expected.
[root@ip-172-31-27-41 ~]# yum install python3
[...]
[root@ip-172-31-27-41 ~]# python3 -m venv toxbase
[root@ip-172-31-27-41 ~]# source toxbase/bin/activate
(toxbase) [root@ip-172-31-27-41 ~]# pip install tox
[...]
tox.ini:
[tox]
skipsdist = True
envlist = py37
[testenv]
skip_install = True
deps = pytest
commands = pytest --version
(toxbase) [root@ip-172-31-27-41 ~]# tox
py37 create: /root/.tox/py37
py37 installdeps: pytest
py37 installed: atomicwrites==1.2.1,attrs==18.2.0,more-itertools==4.3.0,pluggy==0.8.0,py==1.7.0,pytest==3.9.3,six==1.11.0
py37 run-test-pre: PYTHONHASHSEED='4020926433'
py37 runtests: commands[0] | pytest --version
This is pytest version 3.9.3, imported from /root/.tox/py37/lib/python3.7/site-packages/pytest.py
______________________________ summary _________________________________
py37: commands succeeded
congratulations :)
So at least with the shipped Python3 all seems to be well.
To repeat the suggestion above: if you have a system that shows weird behaviour regarding packaging tools and you need a specific Python version, you might be well served by using pyenv. pyenv compiles pretty much all Python versions for you (no root permissions necessary) and makes them available in userspace (in the way the creators intended - e.g. coming with a packaged venv (then providing pip in the venvs) in the case of all modern Python versions).