尝试将django安装到我的虚拟环境中

时间:2020-03-18 16:09:07

标签: django linux ubuntu pipenv

我是linunx和pipenv的新手。我尝试使用“ pipenv install django”在新环境中安装django,并且发生了这种情况:

Installing django…
Adding django to Pipfile's [packages]…
✔ Installation Succeeded 
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success! 
Updated Pipfile.lock (4f9dd2)!
Installing dependencies from Pipfile.lock (4f9dd2)…
An error occurred while installing asgiref==3.2.5 --hash=sha256:3e4192eaec0758b99722f0b0666d5fbfaa713054d92e8de5b58ba84ec5ce696f --hash=sha256:c8f49dd3b42edcc51d09dd2eea8a92b3cfc987ff7e6486be734b4d0cbfd5d315! Will try again.
An error occurred while installing django==3.0.4 --hash=sha256:50b781f6cbeb98f673aa76ed8e572a019a45e52bdd4ad09001072dfd91ab07c8 --hash=sha256:89e451bfbb815280b137e33e454ddd56481fdaa6334054e6e031041ee1eda360! Will try again.
An error occurred while installing pytz==2019.3 --hash=sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d --hash=sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be! Will try again.
An error occurred while installing sqlparse==0.3.1 --hash=sha256:022fb9c87b524d1f7862b3037e541f68597a730a8843245c349fc93e1643dc4e --hash=sha256:e162203737712307dfe78860cc56c8da8a852ab2ee33750e33aeadf38d12c548! Will try again.
  ?   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 4/4 — 00:00:00
Installing initially failed dependencies…
  ☤  ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 4/4 — 00:00:00
[pipenv.exceptions.InstallError]:   File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/cli/command.py", line 254, in install
[pipenv.exceptions.InstallError]:       editable_packages=state.installstate.editables,
[pipenv.exceptions.InstallError]:   File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/core.py", line 1992, in do_install
[pipenv.exceptions.InstallError]:       skip_lock=skip_lock,
[pipenv.exceptions.InstallError]:   File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]:   File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/core.py", line 862, in do_install_dependencies
[pipenv.exceptions.InstallError]:       _cleanup_procs(procs, False, failed_deps_queue, retry=False)
[pipenv.exceptions.InstallError]:   File "/home/codrut/.local/lib/python3.7/site-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: []
[pipenv.exceptions.InstallError]: ['Traceback (most recent call last):', '  File "/home/codrut/.local/share/virtualenvs/Django-B9r4LqTh/bin/pip", line 5, in <module>', '    from pip._internal.cli.main import main', "ModuleNotFoundError: No module named 'pip'"]
ERROR: ERROR: Package installation failed...

要提一下,几分钟前,我在错误的文件夹中安装了django,并且一切正常。 请帮忙!谢谢!

1 个答案:

答案 0 :(得分:2)

在主目录根目录中,添加以下命令以创建环境:

$ python3 -m venv venv此代码将在根目录中创建一个名为venv的文件夹。基本上是虚拟环境文件夹。

然后添加以下命令以激活虚拟环境:

$ source venv/bin/activate

your_project_folder/
 |
 |-- your_main_app_folder/
 |         |
 |         |--Folder_with_controllers/
 |         |            settings.py
 |         |            urls.py
 |         |            ...
 |         | 
 |         |--App_folder/
 |         |--Other_app_folder/
 |
 |--venv/

如果代码正常运行,您的bash应该如下所示: (venv) <the_path_for_the_folder> your_project_folder %

激活环境后,您现在可以安装django和其他软件包。

Ps:确保安装并激活不在your_main_app_folder中的虚拟环境文件夹。