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

SyntaxError: invalid from typing import TYPE_CHECKING #3520

Closed
ninja18 opened this issue Feb 10, 2019 · 8 comments
Closed

SyntaxError: invalid from typing import TYPE_CHECKING #3520

ninja18 opened this issue Feb 10, 2019 · 8 comments
Labels
Status: Awaiting Update ⏳ This issue requires more information before assistance can be provided. Status: Needs More Information This issue does not provide enough information to take further action. Type: Possible Bug This issue describes a possible bug in pipenv.

Comments

@ninja18
Copy link

ninja18 commented Feb 10, 2019

Virtual env was created and I edited the pipfile.lock once before creating the env
Is this a bug or problem with my environment???

Pinning VCS Packages...Branch mil set up to track remote branch mil from origin.
Switched to a new branch 'mil'
✘ Locking Failed! 
Traceback (most recent call last):
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/resolver.py", line 126, in <module>
    main()
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/resolver.py", line 119, in main
    parsed.requirements_dir, parsed.packages)
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/resolver.py", line 85, in _main
    requirements_dir=requirements_dir,
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/resolver.py", line 69, in resolve
    req_dir=requirements_dir
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/utils.py", line 700, in resolve_deps
    from .vendor.requirementslib.models.requirements import Requirement
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/vendor/requirementslib/__init__.py", line 14, in <module>
    from .models.pipfile import Pipfile
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/vendor/requirementslib/models/pipfile.py", line 23, in <module>
    from ..environment import MYPY_RUNNING
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/vendor/requirementslib/environment.py", line 17, in <module>
    MYPY_RUNNING = os.environ.get("MYPY_RUNNING", is_type_checking())
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/vendor/requirementslib/environment.py", line 10, in is_type_checking
    from typing import TYPE_CHECKING
  File "/home/ninja/anaconda/lib/python3.6/site-packages/typing.py", line 133
    def __new__(cls, name, bases, namespace, *, _root=False):
                                              ^
SyntaxError: invalid syntax
File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/resolver.py", line 126, in <module>
    main()
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/resolver.py", line 119, in main
    parsed.requirements_dir, parsed.packages)
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/resolver.py", line 85, in _main
    requirements_dir=requirements_dir,
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/resolver.py", line 69, in resolve
    req_dir=requirements_dir
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/utils.py", line 700, in resolve_deps
    from .vendor.requirementslib.models.requirements import Requirement
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/vendor/requirementslib/__init__.py", line 14, in <module>
    from .models.pipfile import Pipfile
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/vendor/requirementslib/models/pipfile.py", line 23, in <module>
    from ..environment import MYPY_RUNNING
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/vendor/requirementslib/environment.py", line 17, in <module>
    MYPY_RUNNING = os.environ.get("MYPY_RUNNING", is_type_checking())
  File "/home/ninja/anaconda/lib/python3.6/site-packages/pipenv/vendor/requirementslib/environment.py", line 10, in is_type_checking
    from typing import TYPE_CHECKING
  File "/home/ninja/anaconda/lib/python3.6/site-packages/typing.py", line 133
    def __new__(cls, name, bases, namespace, *, _root=False):
                                              ^
SyntaxError: invalid syntax
@frostming
Copy link
Contributor

I think it is fixed in master, isn't it?

@ninja18
Copy link
Author

ninja18 commented Feb 12, 2019

I have installed the latest release 2018.11.26 and i don't find any commit regarding this issue after that.

@techalchemy
Copy link
Member

the master branch is installable via pip install -e git+https://github.com/pypa/pipenv.git@master#egg=pipenv

if you are still encountering this problem installing that way, please let us know.

@techalchemy
Copy link
Member

btw it seems like anaconda installs a broken version of typing?

@techalchemy techalchemy added Type: Possible Bug This issue describes a possible bug in pipenv. Status: Needs More Information This issue does not provide enough information to take further action. Status: Awaiting Update ⏳ This issue requires more information before assistance can be provided. labels Mar 6, 2019
@techalchemy techalchemy added this to the March Release milestone Mar 6, 2019
@techalchemy
Copy link
Member

@frostming did you remove typing from vendored dependencies as well as setup.py here? Why?

@frostming
Copy link
Contributor

frostming commented Mar 17, 2019

@techalchemy

btw it seems like anaconda installs a broken version of typing?

No, it doesn't, the failure was due to the incompatibility between the typing module and the Python interpreter used by venv. @ninja18 was likely to be using python < 3.5 in the venv. See my explanations below.

@frostming did you remove typing from vendored dependencies as well as setup.py here? Why?

Yes, I did. The typing module installed from PyPI has two different implementations. Depending on the python version being used, a py2 compatible version or py>=3.5 version will be installed.

This will bring trouble when venv resolving dependencies, Pipenv's site packages path will be prepended to the sys.path, so incompatibility may exist between Pipenv python and venv python.
The best solution is to avoid shipping pipenv with pre-installed typing module in site packages.

From the above explanation, we can see the real problem here is anaconda has its typing module installed in site packages(I don't know why but it should have been shipped with Python 3.6 under lib path)

Workaround

I don't know why typing is under site packages and it will be better if you can remove it and use the lib/typing instead. Otherwise, you have to install a redundant typing in your venv. @ninja18 let me know if it works for you.

@brainwane
Copy link
Contributor

Just spoke with @techalchemy and he needs more info to decide whether this still needs fixing. @ninja18 can you try what @frostming suggested in #3520 (comment) and tell us whether it worked for you?

@frostming
Copy link
Contributor

This is not a release blocker, moving it out of the milestone.

@frostming frostming removed this from the March 2020 Release milestone Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting Update ⏳ This issue requires more information before assistance can be provided. Status: Needs More Information This issue does not provide enough information to take further action. Type: Possible Bug This issue describes a possible bug in pipenv.
Projects
None yet
Development

No branches or pull requests

5 participants