安装 python 和 pipenv 后无法识别 Pipenv shell

Pipenv shell not recognized after installing python and pipenv

问题介绍 语言版本:Python3.8 操作系统:Windows10 任何其他相关软件:Jupyter Notebook 和 html-requests

上下文:

我正在尝试安装 pipenv 并按照 this tutorial on using pipenv 安装。我只能在添加“-m”后才能成功安装请求(如下面的第二段代码所示)。我什至不知道“-m”是什么意思,也不知道我是怎么知道这样做的。我的目标和预期结果是打开一个 pipenv shell.

实际结果:

之后我在尝试打开 pipenv 时收到此错误 shell:

PS C:\Users\Cullen Harris\desktop\cfeproj> pipenv shell
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 shell
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (pipenv:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我尝试过的事情: 我在错误前插入的代码:

PS C:\Users\Cullen Harris\desktop\cfeproj> pipenv install requests
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 requests
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (pipenv:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Cullen Harris\desktop\cfeproj> python -m pipenv install requests
Creating a virtualenv for this project…
Pipfile: C:\Users\Cullen Harris\desktop\cfeproj\Pipfile
Using C:/Users/Cullen Harris/AppData/Local/Programs/Python/Python38-32/python.exe (3.8.6) to create virtualenv…
[=   ] Creating virtual environment...created virtual environment CPython3.8.6.final.0-32 in 2512ms
  creator CPython3Windows(dest=C:\Users\Cullen Harris\.virtualenvs\cfeproj-xPOGFEhb, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\Cullen Harris\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\Local\pypa\virtualenv)
    added seed packages: pip==20.2.3, setuptools==50.3.0, wheel==0.35.1
  activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

Successfully created virtual environment!
Virtualenv location: C:\Users\Cullen Harris\.virtualenvs\cfeproj-xPOGFEhb
Creating a Pipfile for this project…
Installing requests…
Adding requests to Pipfile's [packages]…
Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
           Building requirements...
Resolving dependencies...
Success!
Updated Pipfile.lock (fbd99e)!
Installing dependencies from Pipfile.lock (fbd99e)…
  ================================ 0/0 - 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

我不明白为什么会遇到这个问题。但是,一种解决方案是使用 pycharm 而不是终端。我不确定它为什么起作用,但确实起作用了!

我遇到了同样的问题,并且花了一天中的大部分时间试图解决这个问题。我决定不用 PyCharm(通过 VS Code)解决它,所以如果有人需要它,就在这里:

首先,确保pip在正确的位置。查看解释器从中提取文件的位置,然后确保文件存在。 (我知道这听起来很愚蠢,但我有 Python38 和 Python39 文件夹,它们安装在一个文件夹中并从另一个文件夹中拉出。Scripts folder 应该包含以下内容 pips

打开命令提示符,导航到文件夹,然后运行python -m venv env。 然后,select 解释器 -- 它 should contain env。 最后,运行 pipenv shell 在终端。

如果您遇到任何问题,请尝试重新加载 window。您现在应该可以使用 pipenv 安装任何外部库了。

Additional resources from Visual Studio Code.

编辑:确保您使用的是 Power Shell and/or Bash,可能无法在命令提示符下工作。

在终端中转到项目目录 (cd project_directory) 并键入此命令以指定虚拟环境位置:
pipenv --venv
在 windows 中,命令的输出是这样的:

C:\Users\man.virtualenvs\BlogProject-K0fflSCh

复制那个,现在写这个命令来激活虚拟环境: 在 windows:
C:\Users\man.virtualenvs\BlogProject-K0fflSCh\Scripts\activate

在 Linux 中使用 bin 而不是脚本。