timothycrosley / deprecated.pies

The simplest (and tastiest) way to write one program that runs on both Python 2 and Python 3.
MIT License
148 stars 7 forks source link

pies2overrides break create a new virtualenv with python3 #48

Closed luzfcb closed 9 years ago

luzfcb commented 9 years ago

This error is very strange. probably related to https://github.com/pypa/virtualenv/issues/671

I could reproduce the problem in another machine. I created new clean vps with Ubuntu 14.04 x64 in the Digital Ocean, login with root user after, I ran the following commands:

download and install latest version of pip and virtualenv on Python2

root@pies2overrides:~# wget -r "https://bootstrap.pypa.io/get-pip.py" -O get-pip.py ; sudo -H python2 get-pip.py virtualenv

check instaled packages with pip freeze:

root@pies2overrides:~# pip freeze
apt-xapian-index==0.45
chardet==2.0.1
Cheetah==2.4.4
cloud-init==0.7.5
configobj==4.7.2
jsonpatch==1.3
jsonpointer==1.0
Landscape-Client==14.12
oauth==1.0.1
PAM==0.4.2
prettytable==0.7.2
pyOpenSSL==0.13
pyserial==2.6
python-apt===0.9.3.5ubuntu1
python-debian===0.1.21-nmu2ubuntu2
PyYAML==3.10
requests==2.2.1
six==1.5.2
ssh-import-id==3.21
Twisted-Core==13.2.0
urllib3==1.7.1
virtualenv==13.1.0
wheel==0.24.0
zope.interface==4.0.5

create a new virtualenv with python3

root@pies2overrides:~# virtualenv -p `which python3` test_env
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in test_env/bin/python3
Also creating executable in test_env/bin/python
Installing setuptools, pip, wheel...done.
root@pies2overrides:~# 

install pies2overrides

root@pies2overrides:~# pip install pies2overrides
Collecting pies2overrides
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading pies2overrides-2.6.7-py2.py3-none-any.whl
Collecting ipaddress (from pies2overrides)
  Downloading ipaddress-1.0.11-py27-none-any.whl
Installing collected packages: ipaddress, pies2overrides
Successfully installed ipaddress-1.0.11 pies2overrides-2.6.7
root@pies2overrides:~# 
root@pies2overrides:~# 

create another new virtualenv with python3

root@pies2overrides:~# virtualenv -p `which python3` test_env2
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
    import base64
  File "/usr/lib/python3.4/base64.py", line 9, in <module>
    import re
  File "/usr/lib/python3.4/re.py", line 324, in <module>
    import copyreg
  File "/usr/local/lib/python2.7/dist-packages/copyreg.py", line 3, in <module>
    from copy_reg import *
ImportError: No module named 'copy_reg'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
    if not enabled():
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
    import re
  File "/usr/lib/python3.4/re.py", line 324, in <module>
    import copyreg
  File "/usr/local/lib/python2.7/dist-packages/copyreg.py", line 3, in <module>
    from copy_reg import *
ImportError: No module named 'copy_reg'

Original exception was:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
    import base64
  File "/usr/lib/python3.4/base64.py", line 9, in <module>
    import re
  File "/usr/lib/python3.4/re.py", line 324, in <module>
    import copyreg
  File "/usr/local/lib/python2.7/dist-packages/copyreg.py", line 3, in <module>
    from copy_reg import *
ImportError: No module named 'copy_reg'
root@pies2overrides:~#

In short, the sequence of commands has been:

wget -r "https://bootstrap.pypa.io/get-pip.py" -O get-pip.py ; sudo -H python2 get-pip.py virtualenv
pip freeze
virtualenv -p `which python3` test_env
pip install pies2overrides
virtualenv -p `which python3` test_env2
dracos commented 9 years ago

This does appear to be pypa/virtualenv#671, yes; the issue is with virtualenv having a python 2.7 packages directory on the path when running python 3.4, leading to much confusion (I have it complaining about reprlib similarly). My workaround is to make sure the virtualenv in which tox is running does not have pies/pies2overrides installed.

timothycrosley commented 9 years ago

Unfortunately, I don't think this is something I can fix, in the meantime for my own projects like isort I've started switching to single file version of pies, called "pie_slice" https://github.com/timothycrosley/isort/blob/develop/isort/pie_slice.py so that they don't run into this kind of issues when used.