简体   繁体   中英

Installed modules not found by Python

I need to use the autogui module to do something in Python. When I run the script, it says that it can't find the autogui module so I installed it with pip install autogui . But when I run the script again it still says me this module doesn't exist.

Try pyautogui - I had the same problem. Instead of autogui , write `pyautogui. Or, if you are running python3 or higher then try:

pip3 install pyautogui.

Method 1:

You're probably having trouble setting up your correct Python Interpreter and working within it,try the following in VSCode.

Ctrl + Shift + p

And enter the following in the field.

python: select interpreter

Select the desired environment and reinstall PyAutoGui

Method 2:

Creating a virtual environment for your project where all your packages will be installed and will be isolated from others, and will have no import errors since it's an environment specifically for the project that you're working on.

I assume you use Windows, so open the command line in your working directory, or open your working directory in VSCode and enter the following in the command-line tool that is provided within VSCode.

The Python installers for Windows include pip. You should be able to access pip using:

py -m pip --version

You can make sure that pip is up-to-date by running the following

py -m pip install --upgrade pip

Installing virtual environment

py -m pip install --user virtualenv

Creating a virtual environment

py -m venv env

The second argument is the location to create the virtual environment. Generally, you can just create this in your project and call it env.

venv will create a virtual Python installation in the env folder.

Finally, to activate the environment run the following command

.\env\Scripts\activate

That will activate your environment.

pip install pyautogui

Make sure to change your interpreter to the one that you just created in the env/bin folder and run your code, or you could just enter the path to the * python file located in the env/bin folder.

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