3

I have both Python 3.7 and 3.6 installed. But in my profile I set to use 3.6 and this is indeed a version that gets reported by which python3.

$ which python3 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3

I then create virtual env by running python3 -m venv venv

And everything in my venv gets linked to the 3.6. I confirm this with ls -la venv/bin and by inspecting venv/pyvenv.cfg.

I activate the venv virtual environment.

I then install a zappa library with pip install zappa.

And when I run zappa deploy, I get an error that Python 3.7 is not supported. Why would a library use the version of Python that is not configured within the virtualenv and how do I make it use the correct version?

(venv) $ zappa deploy
Traceback (most recent call last):
  File "/Users/t/Projects/djzappa/Spheres/venv/bin/zappa", line 7, in <module>
    from zappa.cli import handle
  File "/Users/t/Projects/djzappa/Spheres/venv/lib/python3.7/site-packages/zappa/__init__.py", line 12, in <module>
    raise RuntimeError(err_msg)
RuntimeError: This version of Python (3.7) is not supported!
Zappa (and AWS Lambda) support the following versions of Python: ['2.7', '3.6']

NOTE: I do NOT use virtualenv as everybody is suggesting, and as other existing answers are referring.

enter image description here

Ska
  • 6,658
  • 14
  • 53
  • 74

3 Answers3

5

Use this when you create environment:

virtualenv --python=/usr/bin/python3.6 

But if you want to use venv, first of all, check whether python3 in your terminal refers to the python3.6 as you want.

If not - run your command with the full path to python3.6 instead of sole python3 in python3 -m venv venv.

Edit: why your alias python3 is referring to python3.7 - it probably depends on OS you use and sequence of installation. Hard to say.

artona
  • 1,086
  • 8
  • 13
  • 1
    I don't use virtualenv. I use 'python3 -m venv'. – Ska Nov 19 '18 at 10:29
  • Try using /usr/bin/python36 -m venv; If it does not works either, please install virtualenv. – artona Nov 19 '18 at 10:36
  • $ /usr/bin/python36 -bash: /usr/bin/python36: No such file or directory – Ska Nov 19 '18 at 10:41
  • $ which python3 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 – Ska Nov 19 '18 at 10:41
  • Do you use conda? – artona Nov 19 '18 at 10:42
  • Never heard of conda. – Ska Nov 19 '18 at 10:43
  • I assume that you use `which python3` in the normal, non-environment directory? – artona Nov 19 '18 at 10:47
  • Yes, it was deactivated at the moment – Ska Nov 19 '18 at 10:49
  • 1
    And this file is not a symlink? `/Library/Frameworks/Python.framework/Versions/3.6/bin/python3` – artona Nov 19 '18 at 10:50
  • OMG, this actually reports 3.7 as a version $ /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. – Ska Nov 19 '18 at 11:25
  • 1
    It is even weirder and more disgusting than I thought – Ska Nov 19 '18 at 11:25
  • :| "+" will be sufficient award for debugging your problem for me ;D – artona Nov 19 '18 at 11:32
  • Why is there a simlink to 3.7? I used a normal installer.... Please explain and put it in your answer so I can accept it. I can't accept an answer written in a comment :) – Ska Nov 19 '18 at 11:35
1

As an addition to the accepted answer, be also aware that changing the directory name where your venv is located causes using the default python and pip paths of your system, instead of using the venv one.

pdaawr
  • 436
  • 7
  • 16
-1

The Python version is different from the virtualenv python version and that is why it is complaining. You can recreate your virtual environment(delete the existing one) and use the following command

virtualenv --python=your python version here venv Or

mkvirtualenv venv --python=your python version here

if you want to create your virtual environment using mkvirtualenv command.

mohor chatt
  • 356
  • 1
  • 8