简体   繁体   English

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

[英]Pipenv shell not recognized after installing python and pipenv

Problem Introduction Language version: Python 3.8 Operating system: Windows 10 Any other relevant software: Jupyter Notebook and html-requests问题介绍语言版本:Python 3.8 操作系统:Windows 10 其他相关软件:Jupyter Notebook 和 html-requests

Context:语境:

I am trying to install pipenv and follow along with this tutorial on using pipenv .我正在尝试安装 pipenv 并按照本教程使用 pipenv I was only able to successfully able to install requests after adding a "-m" (as seen in the second chunk of code below).我只能在添加“-m”后成功安装请求(如下面的第二段代码所示)。 I don't even know what "-m" even means nor how I knew to do that.我什至不知道“-m”是什么意思,也不知道我怎么知道要这样做。 My goal and expected outcome is to open a pipenv shell.我的目标和预期结果是打开一个 pipenv shell。

Actual outcome:实际结果:

after that I received this error when I tried to open a 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

Things I have tried: The code I inserted before the error:我尝试过的事情:我在错误之前插入的代码:

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.

I could not figure out why I had this problem.我不明白为什么我有这个问题。 However, one solution was to use pycharm instead of the terminal.但是,一种解决方案是使用 pycharm 而不是终端。 I am not sure why it worked, but it did!我不知道为什么它有效,但确实如此!

I'm having the same issue, and have spent the better part of the day trying to figure it out.我遇到了同样的问题,并且花了一天的大部分时间试图弄清楚。 And I was determined to solve it without PyCharm(through VS Code), so here it is if anyone needs it:我决定在没有 PyCharm 的情况下解决它(通过 VS Code),所以如果有人需要它,这里是:

First of all, make sure the pip is in the right place.首先,确保点在正确的位置。 Look at the place the interpreter is pulling the file from, and then make sure the files exist.查看解释器从中提取文件的位置,然后确保文件存在。 (I know this sounds stupid, but I have Python38 and Python39 folders, and they installed in one and pulled from the other. The Scripts folder should contain the following pips (我知道这听起来很愚蠢,但我有 Python38 和 Python39 文件夹,它们安装在一个文件夹中并从另一个Scripts folder拉出。Scripts 文件Scripts folder应包含以下点子

Open up the Command Prompt, navigate to the folder and run python -m venv env .打开命令提示符,导航到该文件夹​​并运行python -m venv env Then, select the interpreter -- it should contain env .然后,选择解释器——它应该包含 env Finally, run pipenv shell in the terminal.最后,在终端中运行pipenv shell

If you're having any issues, try reloading the window.如果您遇到任何问题,请尝试重新加载窗口。 You should be able to use pipenv to install any external library now.您现在应该可以使用pipenv安装任何外部库。

Additional resources from Visual Studio Code.来自 Visual Studio Code 的其他资源。

Edit: Make sure you're using the Power Shell and/or Bash, may not work on the Command Prompt.编辑:确保您使用的是 Power Shell 和/或 Bash,可能无法在命令提示符下运行。

In the terminal go to the project directory (cd project_directory) and type this command to specify virtual environment location: pipenv --ven The output of the command is something like this:在终端中转到项目目录(cd project_directory)并键入此命令以指定虚拟环境位置: pipenv --ven命令的输出是这样的:

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

Copy that and now write this command to activate the virtual environment: In windows: C:\\Users\\man.virtualenvs\\BlogProject-K0fflSCh\\Scripts\\activate复制它,现在编写此命令以激活虚拟环境:在 Windows 中: C:\\Users\\man.virtualenvs\\BlogProject-K0fflSCh\\Scripts\\activate

In Linux use bin instead Scripts.在 Linux 中使用 bin 代替脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM