Pipenv install Locking Failed!No module named 'json'

雨燕双飞 提交于 2020-06-17 09:12:21

问题


I am cleaning my computer recently.I deleted vstudio2017.

Now my environment

python3.6,win10

Strange things have happened,pipenv seems to be completely invalid.

PS F:\hankspace\flaskproject> pipenv install
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Locking Failed!
Traceback (most recent call last):
  File "c:/users/hank/appdata/local/programs/python/python37/lib/site-packages/pipenv/resolver.py", line 3, in <module>
    import json
ModuleNotFoundError: No module named 'json'
File "c:/users/hank/appdata/local/programs/python/python37/lib/site-packages/pipenv/resolver.py", line 3, in <module>
    import json
ModuleNotFoundError: No module named 'json'

I deleted python3.6 and pipenv in addition reload python3.7 and pipenv. but they have same problem.

PS F:\hankspace\flaskproject> pipenv graph

ERROR:  Traceback (most recent call last):
  File "c:\\users\\hank\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\pipenv\\vendor\\pipdeptree.py", line 6, in <module>
    import argparse
ModuleNotFoundError: No module named 'argparse'

I listed what I filed tried.

  • $ pip install --user pipenv
  • deleted pip reload pip
  • export path

Here is a example that looks a lot like me.Python sees json module but pipenv doesn't. Why?

I guess he may have solved the problem but I’m no enought reputation to comment. I will be grateful if someone can give me some advice.


回答1:


What fixed it for me was adding the following to my system environment variables:

In Windows:

setx /M PIPENV_VENV_IN_PROJECT 1

This will force pipenv to create a ".venv" directory in your project folder instead of the default "virtualenvs" in your user profile directory (this part is what is breaking "pipenv install"). It will also give you the proper ".venv" directory and file structure that corresponds to the way pipenv creates it instead of the way "python -m venv .venv" creates it. From what I've seen, the structures are different.

More information about this issue can be found at the following URL: https://github.com/pypa/pipenv/issues/1382

If you want this same result in Linux, set the variable with the following command:

export PIPENV_VENV_IN_PROJECT=1



回答2:


Thanks to bryan, bryan reminded me,when I choice a new folder and run pipenv shell

[    ] Creating virtual environment...Already using interpreter c:\users\hank\appdata\local\programs\python\python36\python.exe
Using base prefix 'c:\\users\\hank\\appdata\\local\\programs\\python\\python36'
New python executable in C:\Users\hank\.virtualenvs\hankspace-spEtL83E\Scripts\python.exe
Command C:\Users\hank\.virtua...E\Scripts\python.exe -m pip config list had error code 1
Installing setuptools, pip, wheel...

  Complete output from command C:\Users\hank\.virtua...E\Scripts\python.exe - setuptools pip wheel:
  Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
ModuleNotFoundError: No module named 'pkgutil'
----------------------------------------
...Installing setuptools, pip, wheel...done.

Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\pipenv\cli\command.py", line 390, in shell
[pipenv.exceptions.VirtualenvCreationException]:       pypi_mirror=state.pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 2156, in do_shell
[pipenv.exceptions.VirtualenvCreationException]:       three=three, python=python, validate=False, pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 506, in ensure_virtualenv
[pipenv.exceptions.VirtualenvCreationException]:       python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 935, in do_create_virtualenv
[pipenv.exceptions.VirtualenvCreationException]:       extra=[crayons.blue("{0}".format(c.err)),]
[pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call last):
  File "c:\users\hank\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\hank\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 2567, in <module>
    main()
  File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 793, in main
    symlink=options.symlink,
  File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 1088, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 935, in install_wheel
    _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
  File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 1025, in _install_wheel_with_search_dir
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "c:\users\hank\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 886, in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command C:\Users\hank\.virtua...E\Scripts\python.exe - setuptools pip wheel failed with error code 1

Failed to create virtual environment.

Then I found this problem can be traced to virtualenv,Finally I found this post https://itqna.net/questions/16455/problems-trying-create-virtual-environment-pipenv solved my problem

python -m venv .venv 
pipenv shell
pipenv install

it worked!




回答3:


Based on the commands and traceback you shared did you actually create and enter your environment? (pipenv shell)

I ran into a similar issue with it failing to lock after installing packages and it turned out that I had 64-bit and 32-bit Python installed and it was causing conflicts. To fix it, I deleted the 32-bit (Start Menu -> Settings -> Apps) then deleted the virtual environment that I had already created. Navigate to C:\Users\.virtualenvs then delete the folder with the name of your environment. Now you can navigate back to your folder and create the pipenv environment again by calling pipenv shell.




回答4:


Try the following command:

python36ana.exe -m pipenv --python 3.6


来源:https://stackoverflow.com/questions/55429542/pipenv-install-locking-failed-no-module-named-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!