I am a beginner and I want to work with the pygame module. I have already used pip install to install pygame and it says so on my command prompt. On my command prompt it says:
Requirement already satisfied: pygame in c:\users\35192\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (2.1.2)
However, when I try to import pygame in vscode, the module won't import and it says: "ModuleNotFoundError: No module named 'pygame'"
Does anyone know how to fix this?
I solved the problem. I basically just used Ctrl+Shift+P to open up the command palette. From there, I opened "Python: Select interpreter" and then I just changed the python interpreter to be the global one (which I assume is the one used by the command prompt)
As seen here: https://stackoverflow.com/questions/15185827/can-pip-be-used-with-python-tools-in-visual-studio#:~:text=Go%20to%20Tools%20-%3E%20Python%20Tools%20-%3E%20Python,enter%20your%20module%20and%20double%20click%20to%20install.
You have to go to Tools -> Python Tools -> Python Environments in vs code. Then click on your python installation, then pip, and install pygame.
Or you can find where your vs code python installation is, and run this: "directory to vs code python.exe" -m pip install pygame
If you would like to use one python installation everywhere, you can change your vs code interpreter/environment to the python you already have installed on your system. As seen here: https://code.visualstudio.com/docs/languages/python
Related
This question already has answers here:
How to install pygame?
(4 answers)
Unable to install Pygame using pip
(27 answers)
Closed 22 days ago.
I can't use pygame package in Pycharm. I have installed it with pip but I can not use it. When I tried to install it from the error that appeared in the IDE or from 'Python Packages', it gave me an error. I also tried pip install pygame --pre and it's not working. It says that 'Requirement already satisfied:' but I still can not use it. What should I do?
You should be able to left click on the module. It will display a download packages button. You need internet but should be able to download it. You don't to use the command prompt to install packages. That is only for the python IDLE.
Go here and click install. Pycharm using his own registry of packages.
https://imgur.com/a/AZvsBxJ
So, you're using PyCharm, it likely means it has created a new virtual environment when you created your project, to install packages in that environment it's easiest to either use PyCharm's Package Manager or Terminal. In the case of using Python 3.11 you'd need to supply the --pre flag when installing pygame because the full release of 2.1.3 has not yet been released and 2.1.3.dev8 which is a pre release is the latest one that has 3.11 wheels for installation. More information about that particular thing can be found here: https://stackoverflow.com/a/74188087/14531062
So, on PyCharm you'd want to use the Terminal:
When you switch to it, you'll likely find that it basically is PowerShell (unless you have changed it to use CMD which I doubt) (you'll see PS at the start of each line) so the easiest steps to install pygame would be to type in these commands in this order (press the enter key after each line):
cmd
venv\scripts\activate
pip install pygame --pre
After running these commands pygame should be installed in the correct environment and you should be able to import it without any issues.
Screenshot of how it might look when you follow the steps:
I'm trying to use selenium, but can't get python to recognize it.
I installed it first using "pip install selenium" and "pip install webdriver-manager". It is in the folder "C:\Users\{username}\AppData\Local\Programs\Python\Python310\Lib\site-packages\selenium", but I get the error "ModuleNotFoundError: No module named 'selenium'" when I try to import it.(https://i.stack.imgur.com/dVplU.png)
(https://i.stack.imgur.com/wiREJ.png)
Here it is shown as installed with the command "pip list"
(https://i.stack.imgur.com/QhOu7.png)
I also tried uninstalling it and reinstalling with flags that I saw some people say worked, but it didn't make a difference.
(https://i.stack.imgur.com/VTTMU.png)
I only have one python interpreter version installed, 3.10 (so only one python folder, "Python310"). I have pandas in the same site-packages folder which I can import and use no problem.
If anyone knows what the issue might be, please let me know. I can't figure it out for the life of me.
Okay, I solved the issue by completely uninstalling the interpreter which I got from the Microsoft Store and reinstalling it from the official Python website. Now "from selenium import webdriver" works.
Somehow selenium installed in the global scope is not getting recognized within the Virtual Environment of VS Code / PyCharm.
Solution
You need to install Selenium within the Virtual Environment.
Within the Terminal execute the command:
pip install -U selenium
I have successfully installed npTDMS as seen here:
https://pypi.org/project/npTDMS/
If I try to install with command line using either pip or conda I get a message confirming it is already installed, and I see the package at D:\Users\username\anaconda3\pkgs.
On Spyder I have tried using the PYTHON path manager (in the tools menu) to add both:
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0\site-packages\nptdms
As far as I understand this should be enough to use the npTDMS package, however when I try to import I get a ModuleNotFoundError: No module named 'nptdms'.
I'm fairly new to python overall so maybe there is a simple thing I am missing.
This issue comes when there are multiple versions of python or any package you are running at current time. The same issue was with me too when the IDLE was not able to detect the position of where the package is installed.
My suggestion is that uninstall all the versions of python and the module you are using and install them again. Otherwise shift to any other IDLE, in my recommendation - Visual Studio Code.
I am trying to use pytube to download videos but it isn't working. I don't know much about python (or any other programming language) so it is likely that my problem is easy to solve. I have tried reading multiple websites and watching several YouTube videos, but I haven't been able to make it work yet.
I use a MacOS High Sierra 10.13.6;
I have both Python 2.7.16 and Python 3.8.3 versions installed;
I used the terminal to install pytube using "pip install pytube3";
When I try to install again using the same command as above, I think that it is correctly installed, because the terminal shows the following messages:
Requirement already satisfied: pytube3 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (9.6.4)
Requirement already satisfied: typing-extensions in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pytube3) (3.7.4.3)
I am trying to use PyCharm 2020.2.1 (Community Edition)
I think that pytube is also OK in PyCharm, because it appears in "External libraries" under "site-packages"
My problem:
When I open PyCharm, it opens on "main.py". There, I try to write:
import pytube.
But I get the following message:
/Users/applemacosx/PycharmProjects/pythonProject5/venv/bin/python /Users/applemacosx/PycharmProjects/pythonProject5/main.py
Traceback (most recent call last):
File "/Users/applemacosx/PycharmProjects/pythonProject5/main.py", line 1, in <module>
import pytube
ModuleNotFoundError: No module named 'pytube'
Process finished with exit code 1
I have tried searching about this error, but I wasn't able to find anything that I could make work. I would be very grateful if someone could help me understand what I am doing wrong.
What's happening is that you've indeed installed pytube on the python installation on your machine, but Pycharm creates a virtual environment for each new project you create.
So while pytube is installed in the python environment on your machine, it's not installed in this newly created python environment. The solution is to install pytube in the project's virtual environment. There a couple of ways to do that. Probably the easiest would be to go to the terminal window in Pycharm, and execute the pip install command.
It's happening due to virtual environment, which PyCharm creates separately for each and every project. There are many ways to add a library to current project but the easiest way could be to add directly from PyCharm.
Steps:
Go to Top left, click on PyCharm
Then click on Preferences
Now, In the preferences search for Project Interpreter
After this click on + sign to add pytube
Once you click on +, you would see another pop up window, you need to put putube there and select the exact match or the one you are looking for(You can mention the version too).
At last click on Install package. pytube will be install in few seconds and you can start importing in your module.
The below screenshots could help you more:
This question already has answers here:
Python error "ImportError: No module named"
(37 answers)
Closed 3 years ago.
I'm using a mac and typed
pip install pygame
into my terminal.
The terminal said the download was successful, but when I use
import pygame
in IDLE, I get an error.
I've looked at questions similar to this one and have not found an answer. Does anyone know what the problem could be?
Your terminal is referring to a different environment that the one that your IDLE environment refers to. For example Pycharm saves its python packages in the venv folder by default. Pip installing a package through the terminal would not allow you to import the package inside pycharm because you have not installed it in the venv environment.
To fix this, I believe you should use the command
source activate
in order to activate the environment that IDLE is running. You should be able to install it, and import it then.