安装了第三方 python 模块 - 仍然无法导入 (windows)
Installed a third party python module - still won't import (windows)
我正在尝试导入 pyautogui 模块,但错误一直提示我没有安装该模块。
我知道我已经安装了它,只是为了检查,我输入了
pip install pyautogui
进入我的命令行,它 运行 在所有 pyautogui 文件的列表下方,说明它们已经安装在哪个目录中。
所以我认为这是我需要设置路径的问题。我是新手,但谷歌搜索了一下,我想出了如何使用 sys 模块将路径添加到 Python。
所以在我的 python 文本编辑器中输入:
import sys
sys.path
它继续向我显示路径中的所有目录。想想看,pyautogui 的路径不在那里。
所以我通过键入以下内容添加了带有 pyautogui 的目录:
sys.path.append(r'C:\Users\me\ etc.)
它似乎注册得很好。我再次检查 sys.path 瞧,目录已添加。
然而,我接着尝试再次导入 pyautogui,我得到了同样的结果,告诉我它没有安装。
我是初学者,对命令行不是很熟悉。
我做错了什么?
我能够在我的 Windows 系统上安装 "pyautogui"。它可以很好地导入 python 会话。
这是我用来在 miniconda3 上安装 pyautogui 的东西:
conda activate base
(base) c:\python\conda3>pip.exe install pyautogui
如何将 python 重新安装到不同的文件夹
您可能需要删除所有 python 并重新开始。安装过程中,在第一个启动画面上,有一个 "custom" 按钮或类似的东西。单击它时,您可以输入文件夹路径。您可能需要先创建一个名为 "python" 的空文件夹。此示例将假设 python 安装到 "c:\Users\Pedro\python".
如何安装pyautogui模块
在非 conda 设置上:
# Assuming you installed python into C:\Users\Pedro\python\
# cmd.exe window will open at the default directory. Notice the prompt.
c:\Users\Pedro>
# Change directory "cd" into the python root folder.
# Relative path is "cd python".
c:\Users\Pedro>cd python (enter key)
# Or use absolute path
c:\Users\Pedro>cd C:\Users\Pedro\python (enter key)
# The command prompt will change to the new location.
c:\Users\Pedro\python>
# Install pyautogui from this python root location.
c:\Users\Pedro\python>pip.exe install pyautogui
# This will put pyautogui module in the right python folder.
# That is, relative to python root \python\Lib\site-packages\module-name.
您可以检查 python 用户路径的当前 Windows 设置。如果需要,请手动添加 PATH 设置。对于 python,您需要(root、Lib、站点包和脚本)。如果缺少其中任何一个,您可能会收到导入错误,找不到模块。
c:\Users\Pedro\python\
c:\Users\Pedro\python\Lib\
c:\Users\Pedro\python\Lib\site-packages\
c:\Users\Pedro\python\Scripts\
如何编辑Windows环境用户路径
从 Windows 键,搜索框,键入 "environment",您应该会看到 "Edit the System Environment Variables" 项。点击这个。您会看到 "System Properties" window,在 "Advanced" 选项卡上,单击按钮 "Environment Variables"。
接下来你会看到"Environment Variables"windows。顶部有 User "Path"(单击它以突出显示该行)。然后单击 "Edit" 按钮。
现在您将看到 "Edit environment variables" window。看看你是否拥有我上面发布的所有 python 路径。如果需要,单击 "New" 按钮添加路径。您也可以将它们移到顶部。如果您有多个 python 路径,那没关系。把你现在用的移到最上面就可以了。
我正在尝试导入 pyautogui 模块,但错误一直提示我没有安装该模块。
我知道我已经安装了它,只是为了检查,我输入了
pip install pyautogui
进入我的命令行,它 运行 在所有 pyautogui 文件的列表下方,说明它们已经安装在哪个目录中。
所以我认为这是我需要设置路径的问题。我是新手,但谷歌搜索了一下,我想出了如何使用 sys 模块将路径添加到 Python。
所以在我的 python 文本编辑器中输入:
import sys
sys.path
它继续向我显示路径中的所有目录。想想看,pyautogui 的路径不在那里。
所以我通过键入以下内容添加了带有 pyautogui 的目录:
sys.path.append(r'C:\Users\me\ etc.)
它似乎注册得很好。我再次检查 sys.path 瞧,目录已添加。
然而,我接着尝试再次导入 pyautogui,我得到了同样的结果,告诉我它没有安装。
我是初学者,对命令行不是很熟悉。 我做错了什么?
我能够在我的 Windows 系统上安装 "pyautogui"。它可以很好地导入 python 会话。
这是我用来在 miniconda3 上安装 pyautogui 的东西:
conda activate base
(base) c:\python\conda3>pip.exe install pyautogui
如何将 python 重新安装到不同的文件夹
您可能需要删除所有 python 并重新开始。安装过程中,在第一个启动画面上,有一个 "custom" 按钮或类似的东西。单击它时,您可以输入文件夹路径。您可能需要先创建一个名为 "python" 的空文件夹。此示例将假设 python 安装到 "c:\Users\Pedro\python".
如何安装pyautogui模块
在非 conda 设置上:
# Assuming you installed python into C:\Users\Pedro\python\
# cmd.exe window will open at the default directory. Notice the prompt.
c:\Users\Pedro>
# Change directory "cd" into the python root folder.
# Relative path is "cd python".
c:\Users\Pedro>cd python (enter key)
# Or use absolute path
c:\Users\Pedro>cd C:\Users\Pedro\python (enter key)
# The command prompt will change to the new location.
c:\Users\Pedro\python>
# Install pyautogui from this python root location.
c:\Users\Pedro\python>pip.exe install pyautogui
# This will put pyautogui module in the right python folder.
# That is, relative to python root \python\Lib\site-packages\module-name.
您可以检查 python 用户路径的当前 Windows 设置。如果需要,请手动添加 PATH 设置。对于 python,您需要(root、Lib、站点包和脚本)。如果缺少其中任何一个,您可能会收到导入错误,找不到模块。
c:\Users\Pedro\python\
c:\Users\Pedro\python\Lib\
c:\Users\Pedro\python\Lib\site-packages\
c:\Users\Pedro\python\Scripts\
如何编辑Windows环境用户路径
从 Windows 键,搜索框,键入 "environment",您应该会看到 "Edit the System Environment Variables" 项。点击这个。您会看到 "System Properties" window,在 "Advanced" 选项卡上,单击按钮 "Environment Variables"。
接下来你会看到"Environment Variables"windows。顶部有 User "Path"(单击它以突出显示该行)。然后单击 "Edit" 按钮。
现在您将看到 "Edit environment variables" window。看看你是否拥有我上面发布的所有 python 路径。如果需要,单击 "New" 按钮添加路径。您也可以将它们移到顶部。如果您有多个 python 路径,那没关系。把你现在用的移到最上面就可以了。