简体   繁体   中英

Installed a third party python module - still won't import (windows)

I'm trying to import the pyautogui module, and the error just keeps saying I don't have the module installed.

I know I have it installed, and just to check, I typed

pip install pyautogui 

into my command line and it ran down the list of all the pyautogui files saying that they were already installed and in what directory.

So I figured it was an issue where I needed to set the path. I'm new to this but googling around, I figured out how to use the sys module to add paths to Python.

So in my python text editor I typed:

import sys
sys.path

Which proceeded to show me all the directories in the path. Go figure, the path with pyautogui wasn't in there.

So I added the directory with pyautogui by typing:

sys.path.append(r'C:\Users\me\  etc.)

and it appeared to register fine. I checked sys.path again and voila, the directory was added.

However, I then proceed to try to import pyautogui again, and I get the same result, telling me it's not installed.

I'm a beginner and I'm not well-versed in the command line. What am I doing wrong?

I was able to install "pyautogui" on my Windows system. It imported fine into a python session.

This is what I used to install pyautogui on a miniconda3 setup:

conda activate base
(base) c:\python\conda3>pip.exe install pyautogui

How to reinstall python to a different folder

You may need to remove all python and start over. During installation, on the first splash screen, there is a "custom" button or something like it. When you click on it, you can type in the folder path. You may need to create an empty folder named "python" first. This example will assume python is installed into "c:\\Users\\Pedro\\python".

How to install pyautogui module

On a non-conda setup:

# 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.

You can check your current Windows setup for python USER PATH. If you need to, add PATH settings manually. For python, you need (root, Lib, site-packages, and Scripts). If you are missing any of these, you can get an import error, module not found.

c:\Users\Pedro\python\
c:\Users\Pedro\python\Lib\
c:\Users\Pedro\python\Lib\site-packages\  
c:\Users\Pedro\python\Scripts\

How to edit Windows Environment User PATH

From Windows-Key, Search Box, type "environment", you should see "Edit the System Environment Variables" item. Click on this. You'll see "System Properties" window, on "Advanced" tab, click button "Environment Variables".

Next you will see "Environment Variables" windows. Top part has User "Path" (click on it to highlight the line). Then click "Edit" button.

Now you will see "Edit environment variables" window. See if you have all python paths I have posted above. Click "New" button to add paths if needed. You may also move them up to the top. If you have multiple python paths, that is OK. Just move the ones you are using now to the top.

命令-搜索框

环境变量窗口

编辑python Env Var用户路径

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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