折腾:
【未解决】本地搭建和部署运行Django项目
期间,mac中去:
1 | pipenv install -r requirements.txt |
结果报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | pipenv install - r requirements.txt Traceback (most recent call last): File "/Users/crifan/Library/Python/2.7/bin/pipenv" , line 10 , in <module> sys.exit(cli()) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py" , line 764 , in __call__ return self .main( * args, * * kwargs) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py" , line 717 , in main rv = self .invoke(ctx) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py" , line 1137 , in invoke return _process_result(sub_ ctx.command.invoke(sub_ctx )) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py" , line 956 , in invoke return ctx.invoke( self .callback, * * ctx.params) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py" , line 555 , in invoke return callback( * args, * * kwargs) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/decorators.py" , line 64 , in new_func return ctx.invoke(f, obj, * args, * * kwargs) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/core.py" , line 555 , in invoke return callback( * args, * * kwargs) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/vendor/click/decorators.py" , line 17 , in new_func return f(get_current_context(), * args, * * kwargs) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/cli/command.py" , line 254 , in install editable_packages = state.installstate.editables, File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/core.py" , line 1741 , in do_install pypi_mirror = pypi_mirror, File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/core.py" , line 574 , in ensure_project pypi_mirror = pypi_mirror, File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/core.py" , line 489 , in ensure_virtualenv if not project.virtualenv_exists: File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/project.py" , line 272 , in virtualenv_exists if self .pipfile_exists and os.path.exists( self .virtualenv_location): File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/project.py" , line 437 , in virtualenv_location self ._virtualenv_location = self .get_location_for_virtualenv() File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/project.py" , line 294 , in get_location_for_virtualenv return str (get_workon_home().joinpath( self .virtualenv_name)) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/project.py" , line 421 , in virtualenv_name sanitized, encoded_hash = self ._get_virtualenv_hash( self .name) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/project.py" , line 390 , in _get_virtualenv_hash clean_name, encoded_hash = get_name(name, self .pipfile_location) File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/project.py" , line 386 , in get_name hash = hashlib.sha256(location.encode()).digest()[: 6 ] UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 36 : ordinal not in range ( 128 ) |
感觉是需要指定python3
应该是:
1 | pipenv install -r requirements.txt --python 3.x |
但是此处的3.x,没法统一:
- mac本地python3是:Python 3.7.3
- 在线Ubuntu服务器上是:Python 3.5.2
-》
- 要么是mac本地再安装一个python 3.5.2
- 要么是Ubuntu中升级到python 3.7.3
先去试试简单的:
【部分解决】mac中安装python3的多个不同版本
然后给当前路径local设置了python 3.5.2后:
1 2 | ➜ xxx git:(master) ✗ pyenv local 3.5.2 |
接着继续试试pipenv安装3.5.2
1 | pipenv install -r requirements.txt --python 3.5.2 |
问题依旧:
1 2 3 4 5 | ➜ xxx git:(master) ✗ pipenv --python 3.5 install -r requirement.txt 。。。 File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pipenv/project.py" , line 386, in get_name hash = hashlib.sha256(location.encode()).digest()[:6] UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 36: ordinal not in range(128) |
难道此处的pipenv是python2的,不是python3安装出来的?
果然是:
1 2 3 4 | ➜ xxx git:(master) ✗ which pipenv /Users/crifan/Library/Python/2 .7 /bin/pipenv ➜ xxx git:(master) ✗ pipenv --version pipenv, version 2018.11.26 |
所以,感觉或许是:
mac本地需要去把之前python2的pipenv卸载,安装python3的pipenv
1 2 3 4 5 6 7 8 9 10 11 12 | ➜ db brew remove pipenv Error: No such keg: /usr/local/Cellar/pipenv ➜ db pip uninstall pipenv DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date . A future version of pip will drop support for Python 2.7. Uninstalling pipenv-2018.11.26: Would remove: /Users/crifan/Library/Python/2 .7 /bin/pipenv /Users/crifan/Library/Python/2 .7 /bin/pipenv-resolver /Users/crifan/Library/Python/2 .7 /lib/python/site-packages/pipenv-2018 .11.26.dist-info/* /Users/crifan/Library/Python/2 .7 /lib/python/site-packages/pipenv/ * Proceed (y /n )? y Successfully uninstalled pipenv-2018.11.26 |
然后去用pip3安装pipenv
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ➜ db pip3 install pipenv Collecting pipenv Downloading https: //files .pythonhosted.org /packages/13/b4/3ffa55f77161cff9a5220f162670f7c5eb00df52e00939e203f601b0f579/pipenv-2018 .11.26-py3-none-any.whl (5.2MB) 100% |████████████████████████████████| 5.2MB 80kB /s Collecting virtualenv-clone>=0.2.5 (from pipenv) Downloading https: //files .pythonhosted.org /packages/ba/f8/50c2b7dbc99e05fce5e5b9d9a31f37c988c99acd4e8dedd720b7b8d4011d/virtualenv_clone-0 .5.3-py2.py3-none-any.whl Collecting certifi (from pipenv) Downloading https: //files .pythonhosted.org /packages/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd731e598828d380aa/certifi-2019 .3.9-py2.py3-none-any.whl (158kB) 100% |████████████████████████████████| 163kB 106kB /s Requirement already satisfied: setuptools>=36.2.1 in /usr/local/lib/python3 .7 /site-packages (from pipenv) (40.8.0) Requirement already satisfied: pip>=9.0.1 in /usr/local/lib/python3 .7 /site-packages (from pipenv) (19.0.3) Collecting virtualenv (from pipenv) Downloading https: //files .pythonhosted.org /packages/ca/ee/8375c01412abe6ff462ec80970e6bb1c4308724d4366d7519627c98691ab/virtualenv-16 .6.0-py2.py3-none-any.whl (2.0MB) 100% |████████████████████████████████| 2.0MB 216kB /s Installing collected packages: virtualenv-clone, certifi, virtualenv, pipenv Successfully installed certifi-2019.3.9 pipenv-2018.11.26 virtualenv-16.6.0 virtualenv-clone-0.5.3 |
去安装试试,就不会报错了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ➜ xxx git:(master) ✗ pipenv install -r requirement.txt Creating a virtualenv for this project… Pipfile: /Users/crifan/dev/dev_root/projects/xxxCRM/sourcecode/xxx/Pipfile Using /usr/local/opt/python/bin/python3.7 (3.7.3) to create virtualenv… ⠏ Creating virtual environment...Already using interpreter /usr/local/opt/python/bin/python3.7 Using base prefix '/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7' New python executable in /Users/crifan/.local/share/virtualenvs/xxx-felNIzdJ/bin/python3.7 Also creating executable in /Users/crifan/.local/share/virtualenvs/xxx-felNIzdJ/bin/python Installing setuptools, pip, wheel... done. ✔ Successfully created virtual environment! Virtualenv location: /Users/crifan/.local/share/virtualenvs/xxx-felNIzdJ Creating a Pipfile for this project… Requirements file provided! Importing into Pipfile… Pipfile.lock not found, creating… Locking [dev-packages] dependencies… Locking [packages] dependencies… ⠹ Locking... |
【总结】
此处mac中,之前是python2的pipenv,然后用别人的某Django项目的python3的requirements.txt
去安装虚拟环境:
1 | pipenv install -r requirements.txt |
结果报错:
File “/Users/crifan/Library/Python/2.7/bin/pipenv”, line 10, in <module>
…
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe8 in position 36: ordinal not in range(128)
原因:
用python2的pipenv去安装python3的库,会报错。
解决办法:
用python3的pipenv
所以先去卸载旧的python2的pipenv:
1 | pip uninstall pipenv |
再去安装新的python3的pipenv:
1 | pip3 install pipenv |
即可。再去:
1 | pipenv install -r requirements.txt |
就不会报错了。
注:
如果此处只是指定安装时指定python3:
1 | pipenv install -r requirements.txt --python 3.5.2 |
也是不行的。
转载请注明:在路上 » 【已解决】Mac中pipenv install -r requirements.txt报错:UnicodeDecodeError ascii codec can’t decode byte 0xe8 in position ordinal not in range 128