简体   繁体   English

路径找不到Python或软件包

[英]Path can't find Python or packages

I'm new to Windows and using the command line. 我是Windows的新手,正在使用命令行。 I'm having issues with how the path works. 我对路径的工作方式有疑问。

I installed Python 3 using Anaconda on a Windows 10, and I'm using a virtual environment that doesn't seem to recognize python. 我在Windows 10上使用Anaconda安装了Python 3,并且使用的虚拟环境似乎无法识别python。

 $ python --version bash: python: command not found 

In the command line, Python is installed, but many packages like Flask and Pandas also aren't being recognized. 在命令行中,安装了Python,但是许多包(例如Flask和Pandas)也无法识别。 I've used pip install, which works correctly 我使用了pip install,可以正常工作

 $ pip install flask Requirement already satisfied: flask in c:\\users\\dta\\anaconda3\\lib\\site-packages (1.0.2) Requirement already satisfied: click>=5.1 in c:\\users\\dta\\anaconda3\\lib\\site-packages (from flask) (6.7) Requirement already satisfied: itsdangerous>=0.24 in c:\\users\\dta\\anaconda3\\lib\\site-packages (from flask) (0.24) Requirement already satisfied: Werkzeug>=0.14 in c:\\users\\dta\\anaconda3\\lib\\site-packages (from flask) (0.14.1) Requirement already satisfied: Jinja2>=2.10 in c:\\users\\dta\\anaconda3\\lib\\site-packages (from flask) (2.10) Requirement already satisfied: MarkupSafe>=0.23 in c:\\users\\dta\\anaconda3\\lib\\site-packages (from Jinja2>=2.10->flask) (1.0) twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed. You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. 

But then running a program with either of those packages doesn't work and I get a result like this one: 但是然后使用这些软件包中的任何一个运行程序都无法正常工作,结果是这样的:

 Traceback (most recent call last): File "app.py", line 1, in <module> import flask ModuleNotFoundError: No module named 'flask' 

It seems like the path is set, but there's some issue with the command line recognizing it correctly. 似乎已设置路径,但是命令行正确识别它存在一些问题。 I've uninstalled and then reinstalled Python and made sure to check the box 'Add Python to PATH' during the installation but nothing has worked. 我先卸载了Python,然后重新安装了Python,并确保在安装过程中选中“将Python添加到PATH”框,但没有任何反应。 Any ideas on how to fix this? 有想法该怎么解决这个吗?

You most likely do not have Anaconda on your Path. 您很可能在Path上没有Anaconda。 Try: 尝试:

echo %PATH%

if Anaconda is not there, do 如果Anaconda不在那里,请执行

setx PATH “%PATH%;c:\users\dta\anaconda3\scripts;c:\users\dta\anaconda3”

This will set anaconda to Path. 这会将anaconda设置为Path。 Close and Restart CMD 关闭并重新启动CMD

If you have different environments, try 如果您有其他环境,请尝试

conda env list

To activate your environment: 要激活环境:

conda activate environmentName

Remember to use conda install ... over pip as it deals with upgrades and downgrade for compatibility issues. 请记住在点子上使用conda install ...,因为它会处理兼容性问题的升级和降级。

if Anaconda is there, then you must have another Python their too that comes before Anaconda. 如果Anaconda存在,那么您还必须在Anaconda之前安装另一个Python。 That will be selected over Anaconda, unless you rearrange that Anaconda comes first before it. 除非您重新安排Anaconda在其之前排在第一位,否则它将在Anaconda上进行选择。

If you do not want that, you can simply create an environment: 如果您不希望这样做,则可以简单地创建一个环境:

conda create -n awesome python=3.7

Then activate it and install your packages there: 然后激活它并在其中安装软件包:

conda activate awesome
conda install flask
python -V # Python 3.7

To see where Python looks for packages do: 要查看Python在哪里寻找软件包:

python -c "import sys;print(sys.path)"

See where it is looking for packages. 查看它在哪里寻找软件包。

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

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