Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named typing python 2 with pipenv #1176

Closed
ScottEAdams opened this issue Mar 8, 2018 · 12 comments
Closed

ImportError: No module named typing python 2 with pipenv #1176

ScottEAdams opened this issue Mar 8, 2018 · 12 comments

Comments

@ScottEAdams
Copy link

When installing latest version through pipenv on python 2 the typing dependency is skipped causing the importerror.

@hmenager
Copy link

hmenager commented Mar 8, 2018

I've been hit by exactly the same problem, but with python 3.4. A quick investigation suggests the problem comes from commit ac4a2d0. The code itself is correct, but my guess is that pypi wheels have precomputed dependencies, so this part of the code in setup.py does not run on the local machine, so it is not tested against the local version of python.

Here's a test:

$ virtualenv -p python3.4 toto
Running virtualenv with interpreter /usr/bin/python3.4
Using base prefix '/usr'
New python executable in /tmp/toto/bin/python3.4
Also creating executable in /tmp/toto/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
$ cd toto
$ . bin/activate
(toto) $ pip install django_extensions
Collecting django_extensions
  Downloading django_extensions-2.0.2-py2.py3-none-any.whl (217kB)
    100% |████████████████████████████████| 225kB 1.0MB/s 
Collecting six>=1.2 (from django_extensions)
  Using cached six-1.11.0-py2.py3-none-any.whl
Installing collected packages: six, django-extensions
Successfully installed django-extensions-2.0.2 six-1.11.0
(toto) $ python -V
Python 3.4.4
(toto) $ python
Python 3.4.4 (default, Feb  9 2016, 16:12:46) 
[GCC 5.3.1 20160205] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named 'typing'

So, yes, the django_extensions wheel is built for any python version (django_extensions-2.0.2-py2.py3-none-any.whl), it seems. I'm not an expert with python wheels and setup code, but could environment markers (https://www.python.org/dev/peps/pep-0496/) be an alternative?

Now, until this gets resolved in django_extensions, I would advise adding the typing module to your project dependencies.

@dokterbob
Copy link

Confirmed, getting build fails here. https://travis-ci.org/dokterbob/django-newsletter/builds/350810367?utm_source=github_status&utm_medium=notification

Ref jazzband/django-newsletter#246

Fortschritt pushed a commit to Fortschritt/django-newsletter that referenced this issue Mar 8, 2018
dokterbob pushed a commit to jazzband/django-newsletter that referenced this issue Mar 8, 2018
@trbs
Copy link
Member

trbs commented Mar 10, 2018

Please test with Django Extensions 2.0.5 and hopefully that fixes the issues.

@hmenager
Copy link

@trbs I just tested it, it seems to solve the problem for me, thank you!

@trbs
Copy link
Member

trbs commented Mar 11, 2018

awesome, please reopen if it turns out there are other edge cases.

@trbs trbs closed this as completed Mar 11, 2018
dokterbob added a commit to jazzband/django-newsletter that referenced this issue Mar 13, 2018
dokterbob added a commit to jazzband/django-newsletter that referenced this issue Mar 13, 2018
@Azd325
Copy link
Contributor

Azd325 commented Mar 13, 2018

Pipenv still does not find typing on python 2 for me it seems it is the wrong use of the extras_require

    extras_require={
        'with_typing':  ["typing"],
    }

and then
pip install django_extension[with_typing]

For a optional install depending on the python version I would recommend this in the setup.py

install_requires = [
     'six>=1.2',
     'typing;python_version<"3.5"',
]

@trbs
Copy link
Member

trbs commented Mar 13, 2018

Thought there issues with people using older versions of setuptools with that syntax ?

What if we do:

if int(setuptools.__version__.split(".", 1)[0]) < 18:
    assert "bdist_wheel" not in sys.argv, "setuptools 18 or later is required for wheels."
    if sys.version_info[:2] < (3, 5):
        install_requires.append('typing')
elif int(setuptools.__version__.split(".", 1)[0]) >= 36:
    install_requires.append('typing;python_version<"3.5"')
else:
    extras_require[":python_version<'3.5'"] = ["typing"]

So old versions of setuptools just install typing, new versions of setuptools use PEP 508 and the rest uses the more hacky workaround using extras_require.

@trbs trbs reopened this Mar 13, 2018
@trbs
Copy link
Member

trbs commented Mar 13, 2018

please test with master :-)

@Azd325
Copy link
Contributor

Azd325 commented Mar 13, 2018

Seems to work this way

$ cat Pipfile
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[dev-packages]

[packages]
django-extensions = {git = "https://github.com/django-extensions/django-extensions.git", editable=true}

[requires]

python_version = "2.7"

$ pipenv lock -r
-e git+https://github.com/django-extensions/django-extensions.git#egg=django-extensions
six==1.11.0
typing==3.6.4

@trbs
Copy link
Member

trbs commented Apr 17, 2018

released version 2.0.7 hopefully this is permanently fixed :-)

@trbs trbs closed this as completed Apr 17, 2018
@votecoffee
Copy link

votecoffee commented May 19, 2021

For me, this had a root cause in pip upgrading to a version not actually allowed by Python when using pip install -U pip. I had to curl and install the latest python2 pip version using the commands below:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
py get-pip.py

Then all of the usual pip installs worked as expected. But with pip v21, it would attempt to install versions of packages that were not python2 compatible.

@nagugopikrishna
Copy link

For me, this had a root cause in pip upgrading to a version not actually allowed by Python when using pip install -U pip. I had to curl and install the latest python2 pip version using the commands below:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
py get-pip.py

Then all of the usual pip installs worked as expected. But with pip v21, it would attempt to install versions of packages that were not python2 compatible.

worked like a charm... thank you so much saved a hell a lot of time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants