I ran into some problems with some pip installations. I have found a way of installing that works, but I feel like it's wrong.
I installed pygame from the cmd prompt and got this message:
Defaulting to user installation because normal site-packages is not
writeable Requirement already satisfied: pygame in
c:\users\Somenewguy\appdata\roaming\python\python310\site-packages
(2.1.2)
But when I went to pycharm and started my project, I got this message:
Traceback (most recent call last):
File "C:\Users\Somenewguy\Python Projects\new\main.py", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
I then did the pygame pip installation from the terminal in pycharm. But this time I installed it directly into the project folder, and that approach worked.
This is the only way I can import pygame into my projects which I think is weird.
Why do I have to install this package for each project?
If you use a virtual-environment, this is the expected behavior. If you don't want to install it every time, use the system environnement.
Related
I did use the following command in my terminal:
sudo dnf install gtk4-devel
I did get the message below:
[sudo] password for XXXXXXXXXXXXX:
Last metadata expiration check: 1:26:27 ago on Wed 12 May 2021 07:08:28 PM CDT.
Package gtk4-devel-4.2.1-1.fc34.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
When I try to run a scrip (script to get machine information like screen size) that make use of gtk, and use to work before I switch from ubuntu18 to fedora33 (now 34) I do receive the following message
Traceback (most recent call last):
File "/usr/lib64/python3.9/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "/run/media/xxxxxxxxxx/FreeAgent Drive/01ArchivosDeBusqueda/xxxx/Proyectos/Buscador/Codigo/Codigo_de_Ejemplos/monitores.py", line 18, in <module>
import gtk
ModuleNotFoundError: No module named 'gtk'
So I decided to run
python3 -m pip install gtk4
getting the following message
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement gtk4 (from versions: none)
ERROR: No matching distribution found for gtk4
If using sudo dnf install is telling me that the module is already installed, how should I import it to my script: use import gtk or import gtk4 (neither work) or import?
if I type which gtk or which gtk4 it does tell me there is no module gtk
which gtk
/usr/bin/which: no gtk in (/home/xxxxxxxxxxxxxxxxxxxxx/.local/bin:/home/xxxxxxxxxxxxxxxxxxxxxx/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/opt:/opt)
which gtk4
/usr/bin/which: no gtk4 in (/home/xxxxxxxxxxxxxxxxxxxx/.local/bin:/home/xxxxxxxxxxxxxxxxxxxxx/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/var/lib/snapd/snap/bin:/opt:/opt)
So is the module installed or not? How can I verify that, if not how can I install the gtk4
what does it mean “Defaulting to user installation” I am the only user of this machine
what are “normal site-packages”
Is this condition related to permissions, if yes how to fix it for it does not happen again?
I do appreciate any help, please consider I know nothing about computers, computer systems or programing.
I am very new to Python and have reviewed multiple questions here on problems getting packages/modules to import but can't seem to work out what I'm doing wrong. I'm simply trying to import packages and use them in the Spyder console, I'm used to working in R Studio so that's kind of my point of reference.
I run the below code and receive the following messages.
pip install Pillow
Requirement already satisfied: Pillow in c:\users\name\anaconda3\lib\site-packages (7.0.0)
Note: you may need to restart the kernel to use updated packages.
import Pillow
Traceback (most recent call last):
File "<ipython-input-7-f4cbff62aba7>", line 1, in <module>
import Pillow
ModuleNotFoundError: No module named 'Pillow'
I also seem to be getting different results when I run pip install from the console vs from the text editor portion. When I run it from the console, I get the above result about it already being installed. When I run it from the text editor portion, I get the following.
runcell(0, 'C:/Users/name/.spyder-py3/temp.py')
File "C:\Users\name\.spyder-py3\temp.py", line 1
pip install Pillow
^
SyntaxError: invalid syntax
I'm trying to use opencv-python. I imported with pip but it throws ModuleNotFound.
Joshua-Tews-MacBook-Pro:~ nathan$ pip install opencv-python
Requirement already satisfied: opencv-python in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (4.0.0.21)
Requirement already satisfied: numpy>=1.14.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from opencv-python) (1.16.2)
I import with this:
import cv2
I get this error:
Traceback (most recent call last):
File "/Users/nathan/Library/Mobile Documents/com~apple~CloudDocs/CEP/Y4/Capstone Project (Security Cameras System)/cep-ml-capstone/VideoProcessor.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I've look at the answers on this stackoverflow thread, none seem to help: Cannot import cv2 in python in OSX
Others have solutions I completely didn't recognise pertaining to other OS so I skipped those.
Okay I apparently I just had to run the script with Python 3.7 and it worked. I neglected to mention I was using Textmate.
To run scripts in Python 3.7 using Textmate, go to Preferences > Variables. If there isn't a variable named TM_PYTHON, create one then paste this in for the value: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3. Else, just change the value. Be sure to check the box next to the variable.
I have pygame 1.9.2 for Python 3.2+. However, when I try to start up Python with pygame, I receive: "ImportError: DLL load failed: The specified module could not be found." I found the files it needs, but where should I put them?
This is my full error traceback:
Traceback (most recent call last):
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\hg.py", line 1, in <module>
import pygame
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pygame\__init__.py", line 95, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
Most pygame errors in windows 10 are caused by having an out-of-date pygame by installing the compiled .exe version while not installing it from the official source, since their version is different from the PyPi index.
You will have to download the corresponding file suitable for your system from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Then do
pip install c:/path/to/the/wheelfile.whl
You must have installed pygame incorrectly or something went wrong during installation. I would uninstall pygame and reinstall it with the pip command.
Go to the search bar at the bottom left of your desktop (on your taskbar) and enter cmd. This will open the command line interface (CLI). Then go to here: https://pip.pypa.io/en/stable/installing/ and install the file get-pip.py. Once this has been completed, go to the cmd you opened earlier and enter python get-pip.py. This should install pip, setuptools and wheel.
After this, use the command below to install pygame:
pip install pygame
Then try a simple test to see if it works:
import pygame
print(pygame)
Adding modules has been very confusing on my laptop. Whenever I run the pip command, it will appear to be successful – for example:
> pip install selenium
Requirement already satisfied (use --upgrade to upgrade): selenium in /usr/local/lib/python2.7/dist-packages
However, when I try to use it in running python example.py, I get:
Traceback (most recent call last):
File "scriptattempt.py", line 2, in <module>
from selenium import webdriver
ImportError: No module named selenium
Where this happens with pretty much any modules I try to import. Not exactly sure why, I installed python 3 in the past, so I wasn't sure if maybe that's causing problems. I tried python3 example.py, but got the same error for packages in the line before.
I looked in at my site-packages file, at location: /usr/local/lib/python2.7/site-packages
but it's empty. Is this my problem? Is pip not unpacking in the correct location?