python3 cannot load qrcode module [duplicate] - python

This question already has answers here:
How to use pip with Python 3.x alongside Python 2.x
(11 answers)
Closed 6 years ago.
I have installed qrcode package as pip install pyqrcode
Then when I open a python2.x shell and import it there, no errors are given. But when I open a python3 shell and try to import it there it says
ImportError: No module named 'qrcode'
I import it as import qrcode
When I installed the package with pip it says Downloading PyQRCode-1.2.tar.gz, meaning that it is installing the last version. But in pypi
it says that it also support python3.
What's the correct way to import it?

You need to download a separate package for python 3. pip3 install pyqrcode
Then you can access it. Of course you will need to install pip3 first if you don't have it.

Related

Automatically install Python module when code is ran [duplicate]

This question already has answers here:
Installing python module within code
(12 answers)
How to install and import Python modules at runtime
(5 answers)
have python script check for missing modules and install if missing
(3 answers)
Closed 25 days ago.
I am currently finishing a school project making a game of Blackjack. I was using Replit to code and everything was fine. I recently tried to run it at home on Visual Studio Code but it said a module named "matplotlyb.pyplot" wasn't installed. I seem to understand now that you have to install it manually. When my project is done, it will be sent to an external examiner who will review it. Is there anyway to automatically download the module when the code is ran so the examiner won't have to?
Here's what I'm looking for:
import matplotlib.pyplot as plt
#something that installs it if not already installed
Best practice would be to include a requirements.txt file along with your project. The file should contain all the required packages in the format
packagename==version
You could also use the below to generate the requriements.txt
pip freeze > requirements.txt
pip freeze gives you the list of all installed Python modules along with the versions
To run your install all the dependencies, you could just use:
pip install -r requirements.txt
Hope this helps!
Simply wrap things in a try.. except and don't forget to use sys.executable to ensure that you will call the same pip associated with the current runtime.
import subprocess
import sys
# lazy import + install
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
subprocess.check_call([sys.executable, "-m", "pip", "install", "matplotlib"])

Packages importing in Python - Spyder [duplicate]

This question already has answers here:
ImportError: No module named requests
(33 answers)
Closed 4 months ago.
I'm using Spyder with Python 3.9 and Python 3.7 respectively on Mac and Windows and I got the same issue.
I'm trying to import some packages like:
import pythonnet as clr
or
import yfinance as yf
but I get this message:
File "/var/folders/xs/1_m665393ql86dptnsrft5j80000gn/T/ipykernel_2232/2746914347.py", line 1, in <cell line: 1>
import pythonnet as clr
ModuleNotFoundError: No module named 'pythonnet'
I'm sure that I already installed these packages from the prompt. I'm facing the following issue with many packages so I suppose is it related to the working directory. This is the directory where -pip installs the package by default:
/Users/user_folder/opt/miniconda3/lib/python3.9/site-packages
I'd to understand if the issue is related to the directory and how to efficiently setup it.
Thank you in advance.
It may be that when you are running the script you are trying to run a different version of python.
When you run the pip install try python3 -m pip install instead.
If this doesn't work and you are using vscode you can simply click in the bottom right where it states the python interpreter and change what you are using.
If all of that fails to work, then sorry but that's all I can suggest with my current knowledge.

please how can i really import kivy to pycharm [duplicate]

This question already has answers here:
How to deal with Kivy installing error in Python 3.8?
(5 answers)
Closed 2 years ago.
I installed kivy using the command line as instructed in the kivy.. except for last part which says "python -m pip install kivy==1.11.1" which i tried to install according to the instruction from the site...but its giving me error messages so after some research it seems like python 3.8 does no support kivy..but i did install it manually..the main issue now is that i can't import kivy to pycharm it gives me error message "ModuleNotFoundError: No module named 'kivy'"
please what is the correct way to import kivy to pycharm?
Ok, I just solved Your problem. Use this:
python -m pip install kivy[base] kivy_examples --pre --extra-index-url https://kivy.org/downloads/simple/
Write this on PyCharm terminal and you are done!

How to install a package to python which is not default [duplicate]

This question already has answers here:
no module named zlib
(9 answers)
Closed 6 years ago.
I am trying to add zlib package to my python. However, after I install it using "yum install zlib", only the default python (which is python 2.4.3) can import it. While the other python (3.4.4) still cannot use zlib.
When I try to import zlib in python 3.4.4 by
import zlib
It displays
Traceback (most recent call last):
File "< stdin >", line 1, in
ImportError: No module named 'zlib'
My question is, how can I install package to python which is not default?
PS. I installed both zlib and zlib-devel
Thanks
You might need to install the zlib-devel package as well: yum install zlib-devel.
Otherwise you need to post the full error message when you try to run import zlib.

Import problems python [PILLOW] [duplicate]

This question already has answers here:
Package (Python PIL/Pillow) installed but I can't import it
(3 answers)
Closed 7 years ago.
I want to import pillow module but have some problems. I did pip install PillowModule.whl , downloaded from this site
And through PyCharm module install
but when I try to import it I get error ImportError: No module named 'Pillow'
Any advice is helpful.
Pillow is a fork of PIL an older python imaging library
to import Pillow, you do the following:
from PIL import Image
edit: this stackoverflow problem Package (Python PIL/Pillow) installed but I can't import it
is worth a read.

Categories