尝试使用VS Code在虚拟环境中安装Django时出错,但出现错误

时间:2020-06-28 16:56:07

标签: django virtualenv pipenv

我正在尝试学习Django并寻找一种安装方式,它说创建虚拟环境比在全局安装它更好,因此我安装了pipenv很好,但是当我尝试在pipenv中安装Django时给了我这个错误,我在其他任何现有帖子中都找不到答案。

pipenv的安装:

PS C:\Users\max25\Desktop\Python\learning_frameworks.py> pip install pipenv
Requirement already satisfied: pipenv in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (2020.6.2)
Requirement already satisfied: virtualenv in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from pipenv) (20.0.25)
Requirement already satisfied: virtualenv-clone>=0.2.5 in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from pipenv) (0.5.4)
Requirement already satisfied: certifi in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages 
(from pipenv) (2020.6.20)
Requirement already satisfied: pip>=18.0 in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from pipenv) (20.1.1)
Requirement already satisfied: setuptools>=36.2.1 in c:\program files\windowsapps\pythonsoftwarefoundation.python.3.8_3.8.1008.0_x64__qbz5n2kfra8p0\lib\site-packages (from pipenv) (41.2.0)
Requirement already satisfied: distlib<1,>=0.3.0 in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from virtualenv->pipenv) (0.3.1)
Requirement already satisfied: appdirs<2,>=1.4.3 in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from virtualenv->pipenv) (1.4.4)
Requirement already satisfied: filelock<4,>=3.0.0 in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from virtualenv->pipenv) (3.0.12)
Requirement already satisfied: six<2,>=1.9.0 in c:\users\max25\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from virtualenv->pipenv) (1.15.0)

尝试在pipenv中安装Django后出现错误

PS C:\Users\max25\Desktop\Python\learning_frameworks.py> pipenv install django
pipenv : The term 'pipenv' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, 
verify that the path is correct and try again.
At line:1 char:1
+ pipenv install django
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (pipenv:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

3 个答案:

答案 0 :(得分:1)

pipenv不再得到积极开发,也许poetry会更好地满足您的需求。但是,如果您只想使用virtualenv来管理dependencies,我们可以直接使用virtualenv

$ pip install virtualenv
$ virtualenv django
$ source django/bin/activate
$ pip install django

使用source命令后,如果使用的是Linux,则会显示以下内容:

(django) $

这意味着您在虚拟环境中。

答案 1 :(得分:0)

如果您具有Python 3.5或更高版本。 创建虚拟环境就像在命令行中运行以下命令一样容易。 如果您使用的是Windows,那么我会使用它。

python -m venv name
#replace name with your custom name, or if you want to use name of current directory just use a dot (.)

#activate environment
Scripts/activate
#then use simple pip to install dependencies, if you have a requirement text file.
pip install -r ./requirements.txt
pip install django

答案 2 :(得分:0)

我发现我在初次安装Python时并未将Python添加到路径中,所以我不得不重新安装Python(是的,这的确是路径错误)。