question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NameError: name 'unicode' is not defined

See original GitHub issue

Issue description


[hadoop@ip-192-168-0-84 sales-forecast]$ pipenv install --python 3
Virtualenv already exists!
Removing existing virtualenv...
Creating a virtualenv for this project...
Pipfile: /home/hadoop/sales-forecast/Pipfile
Using /usr/bin/python3.4 (3.4.8) to create virtualenv...
⠼ Creating virtual environment...Using base prefix '/usr'
New python executable in /home/hadoop/.local/share/virtualenvs/sales-forecast-ZYWIRznP/bin/python3.4
Also creating executable in /home/hadoop/.local/share/virtualenvs/sales-forecast-ZYWIRznP/bin/python
Installing setuptools, pip, wheel...done.
Running virtualenv with interpreter /usr/bin/python3.4

✔ Successfully created virtual environment!
Virtualenv location: /home/hadoop/.local/share/virtualenvs/sales-forecast-ZYWIRznP
requirements.txt found, instead of Pipfile! Converting...
✔ Success!
Warning: Your Pipfile now contains pinned versions, if your requirements.txt did.
We recommend updating your Pipfile to specify the "*" version, instead.
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
✘ Locking Failed!
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pipenv/resolver.py", line 126, in <module>
    main()
  File "/usr/local/lib/python2.7/site-packages/pipenv/resolver.py", line 119, in main
    parsed.requirements_dir, parsed.packages)
  File "/usr/local/lib/python2.7/site-packages/pipenv/resolver.py", line 85, in _main
    requirements_dir=requirements_dir,
  File "/usr/local/lib/python2.7/site-packages/pipenv/resolver.py", line 69, in resolve
    req_dir=requirements_dir
  File "/usr/local/lib/python2.7/site-packages/pipenv/utils.py", line 700, in resolve_deps
    from .vendor.requirementslib.models.requirements import Requirement
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/requirementslib/__init__.py", line 14, in <module>
    from .models.pipfile import Pipfile
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/requirementslib/models/pipfile.py", line 23, in <module>
    from ..environment import MYPY_RUNNING
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/requirementslib/environment.py", line 17, in <module>
    MYPY_RUNNING = os.environ.get("MYPY_RUNNING", is_type_checking())
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/requirementslib/environment.py", line 10, in is_type_checking
    from typing import TYPE_CHECKING
  File "/usr/local/lib/python2.7/site-packages/typing.py", line 624, in <module>
    AnyStr = TypeVar('AnyStr', bytes, unicode)
NameError: name 'unicode' is not defined
File "/usr/local/lib/python2.7/site-packages/pipenv/resolver.py", line 126, in <module>
    main()
  File "/usr/local/lib/python2.7/site-packages/pipenv/resolver.py", line 119, in main
    parsed.requirements_dir, parsed.packages)
  File "/usr/local/lib/python2.7/site-packages/pipenv/resolver.py", line 85, in _main
    requirements_dir=requirements_dir,
  File "/usr/local/lib/python2.7/site-packages/pipenv/resolver.py", line 69, in resolve
    req_dir=requirements_dir
  File "/usr/local/lib/python2.7/site-packages/pipenv/utils.py", line 700, in resolve_deps
    from .vendor.requirementslib.models.requirements import Requirement
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/requirementslib/__init__.py", line 14, in <module>
    from .models.pipfile import Pipfile
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/requirementslib/models/pipfile.py", line 23, in <module>
    from ..environment import MYPY_RUNNING
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/requirementslib/environment.py", line 17, in <module>
    MYPY_RUNNING = os.environ.get("MYPY_RUNNING", is_type_checking())
  File "/usr/local/lib/python2.7/site-packages/pipenv/vendor/requirementslib/environment.py", line 10, in is_type_checking
    from typing import TYPE_CHECKING
  File "/usr/local/lib/python2.7/site-packages/typing.py", line 624, in <module>
    AnyStr = TypeVar('AnyStr', bytes, unicode)
NameError: name 'unicode' is not defined


$ pipenv --support

Pipenv version: '2018.11.26'

Pipenv location: '/usr/local/lib/python2.7/site-packages/pipenv'

Python location: '/usr/bin/python2.7'

Python installations found:

  • 3.4.8: /usr/bin/python3
  • 2.7.14: /usr/bin/python2.7
  • 3.4.8: /usr/bin/python3.4m

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '0',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.14.72-68.55.amzn1.x86_64',
 'platform_system': 'Linux',
 'platform_version': '#1 SMP Fri Sep 28 21:14:54 UTC 2018',
 'python_full_version': '2.7.14',
 'python_version': '2.7',
 'sys_platform': 'linux2'}

System environment variables:

  • AWS_PATH
  • PYTHONDONTWRITEBYTECODE
  • LESSOPEN
  • SSH_CLIENT
  • LOGNAME
  • USER
  • HOME
  • PATH
  • PS1
  • LANG
  • LESS_TERMCAP_se
  • TERM
  • SHELL
  • EC2_AMITOOL_HOME
  • LESS_TERMCAP_me
  • LESS_TERMCAP_md
  • LESS_TERMCAP_mb
  • HISTSIZE
  • PYTHONFINDER_IGNORE_UNSUPPORTED
  • AWS_ELB_HOME
  • JAVA_HOME
  • EC2_HOME
  • LESS_TERMCAP_ue
  • AWS_AUTO_SCALING_HOME
  • PIP_PYTHON_PATH
  • _
  • AWS_DEFAULT_REGION
  • SSH_CONNECTION
  • AWS_CLOUDWATCH_HOME
  • SSH_TTY
  • OLDPWD
  • HOSTNAME
  • HISTCONTROL
  • SHLVL
  • PWD
  • LESS_TERMCAP_us
  • PIP_SHIMS_BASE_MODULE
  • PIP_DISABLE_PIP_VERSION_CHECK
  • MAIL
  • LS_COLORS

Pipenv–specific environment variables:

Debug–specific environment variables:

  • PATH: /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin
  • SHELL: /bin/bash
  • LANG: en_US.UTF-8
  • PWD: /home/hadoop/sales-forecast

Contents of Pipfile (‘/home/hadoop/sales-forecast/Pipfile’):

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
numpy = "*"
scipy = "*"
scikit-learn = "==0.19.1"
statsmodels = "*"
xgboost = "*"
pystan = "*"
fbprophet = "*"
matplotlib = "==2.2.3"
seaborn = "*"
redis = "*"
sqlalchemy = "*"
mysqlclient = "*"
pyarrow = "==0.11.1"
hdfs = "*"
hdfs3 = "*"
s3fs = "*"
python-dateutil = "*"
chinesecalendar = "*"
pandas = "*"
h5py = "*"
lxml = "*"
openpyxl = "*"
xlrd = "*"
click = "*"
pathlib2 = "*"
python-dotenv = "*"
environs = "*"
joblib = "*"
tqdm = "*"
dask = {extras = ["complete"],version = "*"}

[requires]
python_version = "3.4"

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
frostmingcommented, Jan 4, 2019

@jxltom Let me elaborate it:

User installed pipenv under python2.7, with the dependencies of typing(which only works under python2.7), then work in a virtualenv of Python 3.4, which doesn’t have typing module. However, pipenv lock will use the virtualenv interpreter(python3.4) to call resolver.py, and import the wrong typing module(this is expected because the Pipenv interpreter site-packages is also in PYTHONPATH).

With Python >= 3.5, this isn’t a problem because the stdlib typing module takes priority to Python 2 typing module.

0reactions
jxltomcommented, Jan 4, 2019

@frostming Sounds reasonable 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

NameError: global name 'unicode' is not defined - in Python 3
In a module in this package (algorithm.py) there are some lines that give me error, although it is part of the package. Here...
Read more >
NameError: name 'unicode' is not defined in Python | bobbyhadz
The Python "NameError name 'unicode' is not defined" occurs when using the unicode object in Python 3. To solve the error, replace all...
Read more >
NameError: name 'unicode' is not defined in object_detection ...
The Python3 doesn't have the type unicode anymore and it has been renamed to str. Is there any better way to avoid this...
Read more >
Python :NameError: global name 'unicode' is not defined
Python : NameError : global name ' unicode' is not defined - in Python 3(5solution). No viewsNo views. Dec 14, 2022.
Read more >
NameError: global name 'unicode' is not defined - in Python 3
PYTHON : NameError : global name ' unicode' is not defined - in Python 3 [ Gift : Animated Search Engine ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found