Search code examples
pythonpython-3.xvirtualenvpyenv

Python seems to be running 3.6 even though my virtual environment is configured to run 3.7


I switched to Python 3.7.2 using pyenv. This is confirmed below:

$ python -V
Python 3.7.2

I then created a virtual environment called venv and installed all my dependencies. I can see that these have installed when I run pip list.

When I now run my tests using nosetest I use this command:

nosetests -s -v tests.functional.test_app

The test fails stating I'm missing a dependency. I can see that the dependency has installed when I check pip list. I do however notice that the log trace is referencing Python3.6:

$ nosetests -s -v tests.functional.test_app
Failure: ModuleNotFoundError (No module named 'botocore') ... ERROR

======================================================================
ERROR: Failure: ModuleNotFoundError (No module named 'botocore')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nose/failure.py", line 39, in runTest
raise self.exc_val.with_traceback(self.tb)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 244, in load_module
return load_package(name, filename)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 216, in load_package
return _load(spec)
  File "<frozen importlib._bootstrap>", line 675, in _load
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/Users/me/git/sdk-python/tests/functional/__init__.py", line 2, in <module>
from ..common import *
  File "/Users/me/git/sdk-python/tests/common.py", line 16, in <module>
    import botocore.vendored.requests as requests
    ModuleNotFoundError: No module named 'botocore'

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

I've set the following pyenv local 3.7.2 and pyenv global 3.7.2.

How can I ensure I'm running in correct Python version?


Solution

  • Try which nosetests then run python3.7 output_of_which_nosetests_here