I was making a Tetris game and at the top of the Python code, I put in import pygame, since that was the thing I was thinking of doing and the thing I thought I could only do. My game was complete, the terminal was open, and I ran the code. The terminal gives an error:
Traceback (most recent call last):
File "[removed for safety]", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
So I tried pip installing it with the command pip install pygame, but it just returns a similar error:
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in <module>
from typing import List, Optional
ImportError: No module named 'typing'
I was using
VSCode, with Python version 3.10.5, 64-bit.
First of all you can uninstall python 3.4 from your system, with this link then you can reinstall python from from the python.org website. Then hopefully pip install pygame would work. Or, if pygame is installed run pip uninstall pygame then pip install pygame
File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
Python34 is mentioned in the error code, which indicates that the terminal runtime retrieves python3.4 instead of 3.10 you mentioned.
This indicates that there are multiple versions of Python in your environment.
You can manually select the Python interpreter by using shortcut "ctrl+shift+P" and typing "python: select interpreter" or click this icon to change the interpreter:
After choosing the correct interpreter, you can use command pip install pygame to install python package at the correct python-lib.
Related
I have tried installing ansible through pip install ansible but whenever i get the following error trying to use it:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Scripts\ansible.exe\__main__.py", line 4, in <module>
File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Lib\site-packages\ansible\cli\__init__.py", line 42, in <module>
check_blocking_io()
File "C:\Users\ruan.greyling\AppData\Local\Programs\Python\Python311\Lib\site-packages\ansible\cli\__init__.py", line 34, in check_blocking_io
if not os.get_blocking(fd):
^^^^^^^^^^^^^^^
AttributeError: module 'os' has no attribute 'get_blocking'
I have python and pip installed on the machine.
It looks like this may be a version compatibility issue with Python 3.11. I recommend upgrading to the latest version of Python and then running the command again.
This is why you are getting this error.
Windows without WSL is not natively supported as a control node (more in the documentation)
If you want to run the Control node on Windows use WSL
Good practice code repository and sync to your Linux Control node from Windows machine.
I am install a third party module for the first time.
I am on python 3.10. I have download the openpyxl and extracted the zip folder into:
D:\Users\XXXX\AppData\Local\Programs\Python\Python310\Lib
Then I went to:
D:\Users\XXXX\AppData\Local\Programs\Python\Python310\Scripts
Typed cmd on the address bar and then typed pip install openpyxl.
This is the message returned:
D:\Users\XXXX\AppData\Local\Programs\Python\Python310\Scripts>pip install openpyxl
Traceback (most recent call last):
File "D:\Users\XXXX\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\Users\XXXX\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "D:\Users\XXXX\AppData\Local\Programs\Python\Python310\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
That's because pip is an Alias. The true command is indeed pip3 (or pip2 depending on what Python version you're using). For Ubuntu, there is an useful tool called python3-is-python which creates this alias. Try looking if this also exists for Windows!
Also, make sure you are running the cmd as administrator. It is very common for Windows to not be able to see those commands.
I tried installing requests with "pip install requests" but it shows this
Traceback (most recent call last):
File "c:\users\me\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\me\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\me\AppData\Local\Programs\Python\Python37-32\Scripts\pip.exe\__main__.py", line 9, in <module>
TypeError: 'module' object is not callable
I am on windows 10
That may happens because you don't have proper set PATH of pip in your current machine, instead of use pip install ... you need to specify the python (may vary depending of your python version python3 or python) path and add the -m flag to specify the module that you want to use. in this case pip
try
python -m pip install requests
After having downloaded get-pip.py attempting to install, and opening cmd window in windows 10 I am getting the following error message when I type pip and hit enter:
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\adamh>pip
Traceback (most recent call last):
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pip\__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pip\utils\__init__.py", line 27, in <module>
from pip._vendor import pkg_resources
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 70, in <module>
from pip._vendor import appdirs
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pip\_vendor\appdirs.py", line 510, in <module>
import win32com.shell
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\win32com\__init__.py", line 6, in <module>
import pythoncom
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\pythoncom.py", line 2, in <module>
import pywintypes
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\win32\lib\pywintypes.py", line 124, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Users\adamh\AppData\Local\Programs\Python\Python35\lib\site-packages\win32\lib\pywintypes.py", line 117, in __import_pywin32_system_module__
assert sys.modules[modname] is not old_mod
AssertionError
C:\Users\adamh>
I tried all of the upgrades and such but none of them have been successful. Thank you very much for any help provided. Sincerely, will_learn
First Check if your python is running is properly from command prompt.
Open command prompt and run python it should show your python version else install it properly and add its path in environment variables
Mostly Pip should be already included in Python 2.7.9+ or 3.4+, but if for whatever reason it is not there, you can use the following one-liner.
Download https://bootstrap.pypa.io/get-pip.py and run it with Administrator permission python get-pip.py (If you are on Linux, use sudo python get-pip.py)
You must to add pip's path into Environment Variables. Pip is contained in python's script directory.
Example my case: C:\Python35\Scripts\pip.exe
To add path to environment variables.
Hold Win and press Pause.
Click Advanced System Settings.
Click Environment Variables.
Add C:\Python35\Scripts (Sorry I don't know name of python 3.5's directory) to the Path on System variables.
Restart Command Prompt.
Edit
In another way, you can use pip-Win instead of pip. Read more here: https://sites.google.com/site/pydatalog/python/pip-for-windows
I used Anaconda to install Python 3.4 under Windows 8. At first, everything is fine, and later the system told me that I need to use pip install pip --upgrade to update pip. After I did this, I got some error information on the screen and then pip can no longer be used.
Now when I try to install some packages using pip, there would be some error information:
C:\Users\E440>pip
Traceback (most recent call last):
File "E:\Program Files\Annaconda\lib\runpy.py", line 170, in _run_module_as_ma
in
"__main__", mod_spec)
File "E:\Program Files\Annaconda\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:\Program Files\Annaconda\Scripts\pip.exe\__main__.py", line 5, in <mod
ule>
ImportError: No module named 'pip'
I tried several methods, but still can't fix it. Any suggestions?
You are trying to import pip from your python program; as pip is a linux command, not a python module, this will fail to import the correct program:
import pip
Instead, call it from your bash (linux interpreter):
bash-3.2$ pip install module