2

I have Python 3.6.3 and Python 3.7 installed and when I'm trying to set up a virtual environment with 3.6.3 its throws an error and it seems Python 3.7 is being called instead despite trying to following the suggestions from SO links listed below. Windows 10 and first checking where the Python 3.6.3 executable is:

C:\>py -3.6
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
import sys
print(sys.executable) #C:\Python\python.exe

Now following the accepted answer from here:

C:\>mkdir pyvirtenv && cd pyvirtenv
C:\pyvirtenv>py -3.6 -m venv pyvirtenv

I get the following error:

File "C:\Python37\lib\runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Python37\lib\runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\Python37\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "C:\Python37\lib\venv\__init__.py", line 7, in <module>
    import logging
  File "C:\Python37\lib\logging\__init__.py", line 26, in <module>
    import sys, os, time, io, traceback, warnings, weakref, collections.abc
  File "C:\Python37\lib\traceback.py", line 5, in <module>
    import linecache
  File "C:\Python37\lib\linecache.py", line 11, in <module>
    import tokenize
  File "C:\Python37\lib\tokenize.py", line 33, in <module>
    import re
  File "C:\Python37\lib\re.py", line 123, in <module>
    import sre_compile
  File "C:\Python37\lib\sre_compile.py", line 17, in <module>
    assert _sre.MAGIC == MAGIC, "SRE module mismatch"
AssertionError: SRE module mismatch

It seems the Python 3.7 is being called even with the 3.6 command Then I tried the further alternative suggested by the accepted answer in the previous post, viz: replacing py -3.6 with the executable path but the same error persists

Also tried using virutalenv instead of venv as outlined in the Windows specific solutions here but the final error remains unchanged:

C:\pyvirtenv>virtualenv -p C:\Python\python.exe pyvirtenv
Traceback (most recent call last):
  File "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python\Scripts\virtualenv.exe\__main__.py", line 2, in <module>
  File "C:\Python37\lib\re.py", line 123, in <module>
    import sre_compile
  File "C:\Python37\lib\sre_compile.py", line 17, in <module>
    assert _sre.MAGIC == MAGIC, "SRE module mismatch"
AssertionError: SRE module mismatch

Setting up virtual environment with Python 3.7 is working fine and the above problems remain even after I've removed Python 3.7 completely from the PATH and rebooted.

Thanks

edit

adding output of py -3.6 -m site as requested in comment:

sys.path = [
    'C:\\pyvirtenv',
    'C:\\Python\\python36.zip',
    'C:\\Python37\\DLLs',
    'C:\\Python37\\lib',
    'C:\\Python37',
    'C:\\',
]
USER_BASE: 'C:\\Users\\shanlodh\\AppData\\Roaming\\Python' (doesn't exist)
USER_SITE: 'C:\\Users\\shanlodh\\AppData\\Roaming\\Python\\Python36\\site-packages' (doesn't exist)
ENABLE_USER_SITE: False

edit2

further update based on second round of comments below:

c: \> py -3.6 -c "import site; print(site.__file__)" #C:\Python37\lib\site.py
c:\>python37\lib\site.py
sys.path = [
    'C:\\python37\\lib',
    'C:\\Python37\\python37.zip',
    'C:\\Python37\\DLLs',
    'C:\\Python37',
    'C:\\',
]
USER_BASE: 'C:\\Users\\shanlodh\\AppData\\Roaming\\Python' (doesn't exist)
USER_SITE: 'C:\\Users\\shanlodh\\AppData\\Roaming\\Python\\Python37\\site-packages' (doesn't exist)
ENABLE_USER_SITE: False
shanlodh
  • 1,015
  • 2
  • 11
  • 30
  • Is that the **whole** traceback? Do you perhaps have a `PYTHONPATH` environment variable set? – Martijn Pieters Nov 24 '18 at 18:01
  • Can you run `py -3.6 -m site` and share the output? – Martijn Pieters Nov 24 '18 at 18:02
  • @Martijn Pieters: (a) yes, that's the whole traceback, (b) PYTHONPATH is not set, (c) output of `py -3.6 -m site` added top OP, thanks – shanlodh Nov 24 '18 at 19:38
  • @eryksun: `PYTHONHOME` is not set – shanlodh Nov 25 '18 at 06:37
  • @shanlodh: right, as you can see your 3.6 setup is pretty broken in that it wants to combine Python 3.6 with Python 3.7 paths when importing. That path is taken *probably* from a [`orig-prefix.txt` file in the virtualenv](https://github.com/pypa/virtualenv/blob/8216878248a7f1cc29cb7b64278213bd720d9db0/virtualenv_embedded/site.py#L558-L561). Run `py -3.6 -c "import site; print(site.__file__)"` to find the directory, then look for a `orig-prefix.txt`. – Martijn Pieters Nov 25 '18 at 10:33
  • @shanlodh: do let us know what `print(site.__file__)` produced and what is found in `orig-prefix.txt` before we go hacking the contents. – Martijn Pieters Nov 25 '18 at 10:34
  • @Martijn Pieters: `py -3.6 -c "import site; print(site.__file__)"` produced: `C:\Python37\lib\site.py` and contents of this `site.py` is added as edit2 in OP. I've searched the entire file system with File Explorer and Cortana but there doesn't seem to be a orig-prefix.txt anywhere. Thanks – shanlodh Nov 25 '18 at 16:32
  • Ah, of course, that’ll find he wrong one, what with the path changed. Sorry, that was a bit dumb. Run `py -3.6 -m site -v`. This gives us a *large amount of output* so put that in a pastebin site of some sort. – Martijn Pieters Nov 25 '18 at 16:48
  • @MartijnPieters: the pastebin is here: https://pastebin.com/xEnCdEug and the error output is very similar to what I'd put in the OP – shanlodh Nov 25 '18 at 17:07
  • Sorry, the -v was placed wrong. `py -3.6 -v -m site`. See https://docs.python.org/3/using/cmdline.html#id4 – Martijn Pieters Nov 25 '18 at 18:01
  • @MartijnPieters: here's the pastebin: https://pastebin.com/V5J2hXzK, thanks – shanlodh Nov 25 '18 at 18:48

1 Answers1

0

This is technically not an answer to your question but it's certainly an option to consider if you continue to run through the same issues. In any case, what I suggest you try and do is use Conda virtual environment manager. It seems to work exceedingly well for both windows and unix systems.

You can also read this question to get started with setting up previous python versions environments.

Hope this helps.

Ahmed Ramzi
  • 838
  • 6
  • 7