VSCodium not importing modules in Python - python

I wanted to make a voice assistant importing SpeechRecognition on Python;
I installed PyAudio and SpeechRecognition with the following commands: pip install PyAudio pip install SpeechRecognition on Linux, but when I try to import SpeechRecognition with import speech_recognition as sr, VSCodium doesn't import the module.
But then I tried to import other modules, and the same thing happens... what should I do?

You can check which pip you are using through pip --version, and which python you are using through where python(cmd) or get-command python(PowerShell). Make sure pip matches up with the python interpreter you are using.
If it's not, you can try to reopen the terminal with the shortcut 'Ctrl+Shift+`'. And then to check the pip version again.
If it still not matches up with the interpreter. That's maybe this environment hasn't installed the pip in this environment.

I think its main reason is on Linux pip is for python 2 while pip3 is for python 3.
If you are using py3 using pip3 may help. Other reasons may include a virtual environment you are on.If vscodium does not automatically activate it or whatever extension you are using do not run in the virtual environment it may not find the packages you installed. you can try these commands:
Example:
pip3 install PyAudio
pip3 install SpeechRecognition
python3 main.py

Related

Have multiple Python IDEs, have problems with all of them, can't get any of them to recognise pygame [duplicate]

I'm trying to install Pygame. I am running Windows 7 with Enthought Python Distribution. I successfully installed pip, but when I try to install Pygame using pip, I get the following error:
"Could not install requirement Pygame because of HTTP error HTTP error
400: Bad request for URL ..."
I can't find anything about this issue with a Google search, but I did find another Stack Overflow question that prompted the asker to use the following command:
pip install hg+http://bitbucket.org/pygame/pygame
This gave me the following error:
Cannot find command hg
I'm not sure what else to do, as everything I find with a Google search is for Mac, so I don't know how well I can follow those instructions on Windows.
Steps to install PyGame using pip
Install build dependencies (on linux):
sudo apt-get build-dep python-pygame
Install mercurial to use hg (on linux):
sudo apt-get install mercurial
On Windows you can use the installer: Download
Use pip to install PyGame:
pip install hg+http://bitbucket.org/pygame/pygame
If the above gives freetype-config: not found error (on Linux), then try sudo apt-get install libfreetype6-dev and then repeat 3.
Alternative way:
# Grab source
hg clone https://bitbucket.org/pygame/pygame
# Finally build and install
cd pygame
python setup.py build
sudo python setup.py install
Try doing this:
sudo apt-get install mercurial
sudo pip install hg+http://bitbucket.org/pygame/pygame
An update to this may be required, as it stands in version 1.9.1 it should simply install using:
pip install pygame
However, it look like there is a bug with their pypi repository, see:
https://bitbucket.org/pygame/pygame/issues/59/pygame-has-no-pypi-page-and-cant-be
So, if you want the most recent release, you have to point directly at the ftp file ala:
pip install http://www.pygame.org/ftp/pygame-1.9.1release.tar.gz
I suppose this will be fixed in the 1.9.2 release but for now this works.
I would note that the answer supplied by Pratyush works as well, but requires the user to install mercurial if they don't have it and downloads the trunk version, so really, not ideal unless you absolutely need it.
Caveat: I'm not familiar with the Enthought Distribution, so this might not help.
As you're trying to install on Windows, if you don't want to have to mess around with C compilers, there are pre-built binary wheels for pygame here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Select a package appropriate to you python version[0] and Windows architecture [1]. Download to C:\Users\User\Download\pip install E:\env\pygame-1.9.2a0-cp27-none-win_amd64.whl and install with pip install E:\env\pygame-1.9.2a0-cp27-none-win_amd64.whl
Mercurial binaries can be found on the same page, if you would like to install from source. This method would mean compiling pygame from source, for which you probably want to use this compiler package.
[0] python --version
[1] powershell "gwmi win32_operatingsystem | select osarchitecture"
The command below worked for me on Mac OS X El Capitan:
pip3 install pygame
Install on MAC:
brew install homebrew/python/pygame
Just
sudo pip install pygame
worked for me
Had this issue on macOS Sierra, where apt-get doesn't work.
Managed to solve the issue through the following steps:
First I had to install the Mercurial via Brew:
brew install mercurial
Then, I had to install Pygame dependencies:
brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi
Finally I used pip3 to install Pygame:
pip3 install pygame
Hope this helps!
Try
python3 -m pip install -U pygame --user
This worked twice for me on windows 7 and windows 10
The most current, the best way to install pygame is always available at:
https://www.pygame.org/wiki/GettingStarted
How to use pip depends on the operating system. So unless you have always updated and tested answers for 15 different operating systems then just send people to that page. All answers to this question are wrong for various different operating systems.
Currently, for windows, this is the way to install it in the cmd prompt. (If you already have pip installed, and people know what pip is... best just send people to the GettingStarted page).
py -m pip install pygame --user
I did use these instructions here from the official site.
But i had to change the python3 part of the command to just py.
Try: python -m pip install pygame
Or: py -m pip install pygame
Try pip install pygame or pip3 install pygame.
These should work for you.
If this does not work for you put -m before pip and python before
-m.
If putting -m does not work try reinstalling python
If you are working on windows, the command below should work fine
pip install pygame
If you are working on Linux, the command below should work fine
sudo apt-get install python-pygame
Type this in command prompt
pip install pygame
or
py -m pip install pygame
WINDOWS
If you are on a windows 10 device then you should use this command but first make sure you have Python installed from https://python.org, if you do run this in command prompt
py --version
and then whatever version it says you have (which you downloaded) keep it in mind we will use it later for now just incase try to upgrade pip incase you are on a outdated version I will be using 3.9 for the version for the rest of this as an example
py -3.9 -m pip --upgrade pip
After that if you have it already satisfied or it upgraded run this command in command prompt
py -3.9 -m pip install pygame
And wait for it to download
And to make sure it worked run this
py -3.9 -m pygame --version
If it shows the version you downloaded it!
MacOS
For MacOS do the same but then run this command to install it
python3 -m pip install -U pygame --user
or if it wont work
py -3.9 -m pip install -U pygame --user ( or just pip3 )
to see if it worked run this
python3 -m pygame.examples.aliens
or
py -3.9 -m pygame.examples.aliens
I hope this helped
I have never used Enthought distribution, but you could try to use Anaconda distribution which is also great too.
Anaconda Distribution (Any OS):
From the docs:
Update conda to the current version.
Type the following:
conda update conda
If a newer version of conda is available, type y to update:
Proceed ([y]/n)? y
Check to see if a package you have not installed named
“pygame” is available from the Anaconda repository (must be
connected to the Internet):
conda search pygame
Conda displays a list of all packages with
that name on the Anaconda repository, so we know it is available.
Install this package into the current environment:
conda install pygame
Check to see if the newly installed
program is in this environment:
conda list
Install on Windows (both python 2.7 and 3.7):
pip install pygame
Install on raspberry pi:
sudo pip3 install pygame (python 3.7)
sudo pip install pygame (python 2.7)
I think if you go to Command Prompt and type
py -m pip install pygame
that's what works for me
Here is a way: sudo install pygame Rasberry pi has it ready-installed
Install python 3.8 from python.org
Then install pygame (2.0) like this
pip install pygame==2.0.0.dev10
Make sure script path is registered in environment variables,
Make sure the python path is registered in environment variables,
also you dont have to enter entire url just write like this(windows only I dont use mac)
pip
pip install pygame
hope it work
command to install pygame is:
pip install pygame
run it in command prompt
Try doing this for python3:
python3 -m pip install pygame==1.9.6
and this for python2:
python -m pip install pygame==1.9.6
You don't have to type in the entire url. Just simply go to command prompt (windows) or terminal (mac) and then type in:
[windows] pip install pygame
[mac] python -m install pygame
hopefully that works :)
To install pygame with pip, use the following commands in the Command Prompt on Windows.
py -m pip download pygame
then...
py -m pip install pygame
You only have to do the download pygame one if it doesn't work when you use the install pygame command by itself.
You type py -m to show that it is using the module pip, which can be accessed through the command prompt.
This is for Windows. For Mac OS, use python -m pip install pygame
I know that there are already lot's of answers, but if you want to download a specific version of pygame, you can use pip:
pip install pygame==1.9.6
Pygame 1.9.6 is the latest version at the time of writing.
Pygame tells you how to install it here, in my personal experience this is what I do on windows to install it, open up command prompt and type python -m pip install pygame if that fails, check if you have more than one version of python installed if so you need to specify what version for example python3.5 -m pip install pygame the reason we do this from command prompt is that in the Python shell it doesn't understand what pip install is just to break it down a little python -m calls a python module in this case we want pip the next two arguments are what we want pip to do and what module/addon we want the action to be applied too

Python - Notion API - Can't import module

I'm trying to use Notion API for some automation processes but I am having some trouble importing the packages and I already try a lot of imports. I've this code:
from notion_database.database import Database
my_token = "my_token"
D = Database(integrations_token=my_token )
print(D.list_databases(page_size=100))
To run this code I made the following imports:
pip install notion-database
pip install notion-py
pip install "notion==0.0.25"
pip install notion
All of them were installed correctly and I don't have my script name as "notion.py" :D
But when I run my code I got:
from notion_database.database import Database
ModuleNotFoundError: No module named 'notion_database'
Does anyone know what I am doing wrong?
Thanks for the help!
It looks your code is fine.
More likely, your python and pip points onto two different python versions.
I would suggest you create an environment (virtualenv or pyenv) and reinstall the packages using this command:
sudo python -m pip install notion-database
sudo python -m pip install notion-py
sudo python -m pip install "notion==0.0.25"
sudo python -m pip install notion
maybe you have not install notion successfully.
try to replace pip install notion
to pip install notion --user
,after that maybe there is no error with run "import notion".
good luck!

Python 3 cannot find a module

I am unable to install a module called 'jieba' in Python 3 which is running in Jupyter Notebook 6.0.0. I keep getting ModuleNotFoundError: No module named 'jieba' after trying these methods:
1. import jieba
2. pip3 install jieba
Can anyone help? Thank you.
pip3 in the terminal is almost certainly installing your package into a different Python installation.
Rather than have you hunt around for the right installation, you can use Python and Jupyter themselves to ensure you are using the correct Python binary. This relies on three tricks:
You can execute the pip command-line tool as a module by running python -m pip .... This uses the pip module installed for the python command, so you don't have to verify what python installation the pip3 command is tied to.
You can get the path of the current Python interpreter with the sys.executable attribute.
You can execute shell commands from Jupyter notebooks by prefixing the shell command with !, and you can insert values generated with Python code with {expression}
You can combine these to run pip (to install packages or run other commands) against the current Python installation, from Jupyter itself, by adding this into a cell:
import sys
!{sys.executable} -m pip <pip command line options>
To install your jieba package, that makes:
import sys
!{sys.executable} -m pip install jieba
If you are using Anaconda, then you could also install the conda package for jieba; the package does not require any platform-specific dependencies or compilation, but it may be more convenient for you or necessary to install other packages that do have such requirements and have pre-compiled conda packages.
In that case, tell the conda command about your Python executable:
import sys
!conda install --yes --prefix {sys.prefix} <package name>

"no module named PyPDF2" error

I use Spyder, with Python 2.7, on a windows 10. I was able to install the PyPDF2 package with a conda command from my prompt. I said installation complete. Yet, If I try to run a simple import command:
import PyPDF2
I get the error:
ImportError: No module named PyPDF2
How can I fix this?
In my case, I was trying to import 'pyPdf2' instead of 'PyPDF2'. Observe the case.
import PyPDF2
is correct.
If you use python3 maybe
apt-get install python3-pypdf2
I faced the same problem. But, In my case,
I previously installed Python3 separately from official website and was using without any issues
Then later I installed Anaconda package distribution software which itself has another Python3 installed in corresponding directory.
So, when I installed PyPDF2, it installed normally and while importing throws an error, because the base path of python3 was changed to be used with Anaconda.
Then I opened Anaconda prompt and installed PyPDF2 there and tried to import. It worked!!
Then I can use it from any command prompt in my Windows PC. Or else you can delete Anaconda and everything works normally. Its just a conflict of two pythons in my pc.
Conclusion: Try any overlapping softwares in your PC(in my case Anaconda prompt) and try their CMD to install packages and import. If I wanted to install any package I have to go to Anaconda prompt and install it and importing that modules works anywhere without any error. So from now on wards I'm only using Anaconda prompt as my default installation prompt.
This is the case which I followed for python3. For python2 try with pip:
pip install PyPDF2
I had this problem too when I tried to import PyPDF2 like this:
sudo apt-get install python-pypdf2
When running some simple script with import PyPDF2, I would get an error like this:
ImportError: No module named PyPDF2
The solution was to also install pdfmerge, like this:
pip install pdfmerge
How to install Python packages on Windows, Mac, and Linux for various versions of Python which are simultaneously installed:
I have multiple versions of Python installed on my Windows 8.1 machine (Python 2.7, 3.5, and 3.7). This created problems (confusion, I should say). You must therefore be very explicit when installing packages. Ex:
py -3.7 -m pip install PyPDF2 # on Windows
python3.7 -m pip install PyPDF2 # on Mac and Linux
INSTEAD OF the more generic:
pip install PyPDF2 or
pip3 install PyPDF2
And to upgrade pip, be very specific in your python version, like this:
py -3.7 -m pip install --upgrade pip # on Windows
python3.7 -m pip install --upgrade pip # on Mac and Linux
INSTEAD OF the more generic:
py -3 -m pip install --upgrade pip # on Windows
python3 -m pip install --upgrade pip # on Mac and Linux
Now, I can run python 3.7 with py -3.7 on Windows, or with python3.7 on Linux, and since I did py -3.7 -m pip install PyPDF2 on Windows, or python3.7 -m pip install PyPDF2 on Linux or Mac, the import PyPDF2 command works! Previously, since I had only done pip3 install PyPDF2, the import PyPDF2 command only worked if I ran py -3.5 on Windows or python3.5 on Linux, oddly enough, since apparently that was my "default Python3 version" which the more generic pip3 install PyPDF2 command must have installed the PyPDF2 module into. I think it has something to do with the fact that I installed Python 3.5 for all users, but Python 3.7 for only my user account, so the different pip install commands were placing the installed packages into different locations, with the 3.5 version being the "default" Python3 install location.
See more here: https://docs.python.org/3/installing/index.html:
... work with multiple versions of Python installed in parallel?
On Linux, Mac OS X, and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
Appropriately versioned pip commands may also be available.
On Windows, use the py Python launcher in combination with the -m switch:
py -2 -m pip install SomePackage # default Python 2
py -2.7 -m pip install SomePackage # specifically Python 2.7
py -3 -m pip install SomePackage # default Python 3
py -3.4 -m pip install SomePackage # specifically Python 3.4
When using pip, it usually gets installed in Python 2+ so try
pip3 install PyPDF2
I had the same issue and fixed it when switching Python compiler (bottom left corner on Visual Studio Code) . Try on different versions and eventually it should work.
Im following a UDEMY course here. Im using Anaconda prompt and jupyter notebook.
I encountered the same issue as OP. What I did to have the library working:
restart the environment
go to your anaconda prompt
control c to stop the running instance
conda activate ***your_env_here***
pip install PyPDF2
(in my case open the jupyer notebook) jupyter notebook
You can now import the library without the error. import PyPDF2
Hope this works for you.
I encountered the same issue today while doing Udemy course.
try the following:
type this
import sys
!{sys.executable} -m pip install PyPDF2
then
import PyPDF2
Hope it works for you too.

How can I pip freeze and get only pip --user installs, no system installs?

I have dutifully uninstalled all the Python packages I installed with sudo pip install and installed them with pip --user install instead. Yay me :)
On Ubuntu, I know I can find the relevant binaries at /home/<USERNAME>/.local/bin and the packages themselves at /home/<USERNAME>/.local/lib/python2.7/site-packages ... but navigating there is not as simple as good old pip freeze.
How can I pip freeze and get only the packages I installed with pip --user install rather than all the Python packages, including those installed via apt?
Currently pip does not have any such options. So with default pip its not possible. (and I submitted a feature request and now there is a working PR too!)
However I wrote a little script, which does solve your problem:
# pip_user_installs.py
import sys
import pkg_resources
for module in pkg_resources.working_set:
if sys.argv[1] in module.location:
print module.project_name
usage:
$ python pip_user_installs.py $HOME
It's fairly easy in recent versions of pip (the PR in the other answer is now part of pip).
pip freeze --user
This will output a list of packages currently installed to the user's site-packages.

Categories

Resources