Python Modules do not import yet requirement already satisfied - python

I am importing two python modules on my school computer (I cannot use cmd, I do not have enough experience with powershell), pygame and pyglet. I imported these modules last year and had no problems, this year I have started having problems. I tried reinstalling them.
I have imported them via pip.
import pip
pip.main(["install", "--user", "pygame"])
and
import pip
pip.main(["install", "--user", "pyglet"])
It says that this requirement has already been meet.
When I import it into my code it says
I have tried other methods and they all return the same result.
What can I do?

If restarting vscode doesn't work to cause pylance to find new packages, it sounds like there's a mismatch between the interpreter you're using to run your programs (and where you installed the packages via pip) and the interpreter vscode/pylance is using for language support.
With those restrictions, try this:
First, create a script with
import sys
print(sys.version)
print(sys.executable)
and run it (however you're running scripts).
You should get output like:
3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
C:\Python\Python310\python.exe
Then, in the bottom right of vscode there's a statusbar and at the right side you should see something like:
Here it shows that vscode is using the 3.10.2 64-bit version of the interpreter.
If you click the version label (3.10.2 64-bit in my case), you should get a pop-up at the top of your screen, like:
Make sure you select the interpreter that you're using (as identified by the output of that simple 3-line script -- both the interpreter version and the path).

For me this was a version mismatch: VSCode was using a different interpreter version (3.10) than the packages were installed for (3.9).
You can correct this by clicking the Python version in the status bar (to the right of the word Python). Multiple options should show up, switching to 3.8.9 worked for me.

Related

Pycharm not recognizing installed BeautifulSoup4 module

I have trouble with Pycharm recognizing installed modules. I'm using Pycharm 2018.2.4 CE with Python 3.7 x64, on Windows 10. I don't have Python 2.x installed. I installed requests and BeautifulSoup4 from command line using 'pip' and 'pip3' commands. Pip list and Pycharm is seeing installed module in interpreters list but when I enter my code is grayed out like none of those were installed:
Grayed out code
Interpreter settings
I tried everything - reinstalling both Python (x64 and x86) and Pycharm, installing/upgrading/uninstalling BeautifulSoup4 and bs4, I also tried every solution I could find on stack or google, seems like few people had similar issue but no one gave them any final answer. Does anyone know how to fix this under Windows 10?
See if this helps:
Go to the following path:
File/ Settings/ Project: Project_Name/ Project Interpreter
Click on the plus sign on the right, find the module there and install it.
Also, if they are gray, it's because you have imported them but haven't used them yet. The only one which might have a problem is the last one with the red lines maybe.
This was discussed here
Also, below should be changed
from bs4 import BeautifulSoup

ImportError: No module named 'matplotlib'

Brand new to Python (typically program in MSDN C#) and I'm trying to make use of the matplotlib to generate some graphics from .csv files
I've downloaded & installed Python as well as Anaconda onto my Windows 10 machine, the versions are Python 3.5.2 and Anaconda 4.1.1
I open up the Python "notepad" interface and do
import matplotlib.pyplot as plt
plt.plot([1,2,3],[3,2,1])
plt.show()
but when I run the code I get the error:
ImportError: No module named 'matplotlib'
I've looked at some other posts for this but they all seem to be in regard to Mac OSX or Linux. Some have pointed to multiple installs of matplotlib, but I haven't turned up such a situation so far. What might be causing this, or how can I troubleshoot it?
**Edit:
The path returned to me from the import sys recommended in the comments gave me this response
['C:\Users\a.watts.ISAM-NA\Desktop',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\python35.zip',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\DLLs',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib\site-packages',
'C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\lib\site-packages\setuptools-26.1.1-py3.5.egg']
You essentially have 2 versions of python on your system - the standard one you downloaded and the one that ships with Anaconda. When you are running code in the IDLE you are using the standard version (in C:\Users\a.watts.ISAM-NA\AppData\Local\Programs\Python\Python35-32\python.exe) where matplotlib isn't installed which is why you are getting the error.
You need to use the Anaconda version (C:\Users\a.watts.ISAM-NA\AppData\Local\continuum\anaconda3\python.exe) that comes with the scientific stuff already setup. It looks like your system is using this one from the cmd so if you run scripts from there it should use the Anaconda version. If you want to use something more interactive you can also use spyder - the Anaconda version of the IDLE - or run jupyter notebook from cmd to get a browser based platform for interactive development

python does not find wxPython

In order to start building a gui I've decided to install wxPython, however I can't get it working. I run python 2.7.6 (in IDLE it shows: Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32) and it works fine.
When I however try to install a 32 bit or 64 bit version of wxPython from http://www.wxpython.org/download.php it doesn't work, meaning that when I run:
import wx
I get the following message:
Traceback (most recent call last):
File "C:\Users\****\Desktop\Python GUI test\test1.py", line 2, in <module>
import wx
ImportError: No module named wx
I think it might go wrong with the place where it installs wxPython. Normally however it uses the right directory automatically. It tries to install in the following dir:
C:\Users\****\AppData\Local\Enthought\Canopy32\User\Lib\site-packages
Which is in a program called Canopy which I once installed but don't know how to get rid off. I've installed it in this dir and I've also installed it within the dir where Python is installed:
C:\Python27\Lib\site-packages
Both of these locations don't work.
Anyone has an idea where things go wrong?
I would suggest to clean up your installations. Canopy is part of Enthought, so if you don't need this anymore de-install it, I would think you can do that from: Control Panel\All Control Panel Items\Programs and Features
Then re/install the Python version you want to use, would suggest 2.7.8 32 bit and then install wxPython 3.0.1 32 bit for Python 2.7.
To test it do not use "Idle" as it is written in Tkinter, which will cause conflicts with wxPython. Just test it with
c:\Python27\python.exe
import wx

vim-ipython failed on Windows 7

I installed iPython by Anaconda on Windows 7. (There's no python installed previously). I can run ipython without problem.
Then I installed vim-ipython plugin. In vim, when I run
:IPython
I got this:
E492 Not an editor command.
I checked vim version:
:version
+python/dyn
I checked (in vim)
:python import sys
E370 Could not load python27.dll
Run python on cmd:
Python 2.7.5 |Anaconda 1.7.0 (64-bit)| (default, Jul 1 2013, 12:37:52) [MSC v.1500 64 bit (AMD64)]
Could you please tell me what is wrong with this installation?
Thank you.
Edit:
I tried (in Vim):
:echo has("python")
0
I get really confused!
Edit 2:
Thanks for everybody's help. I decide to build/compile vim 64-bit on windows. I've downloaded MinGW-w64, but don't know how to use it: I can't find 'make'. (I remember there's mingw-32-make in the 32 bit version, but none in the 64-bit version.)
On windows for vim to find python DLL path to it must be present in $PATH. There are multiple ways to achieve this:
Editing registry. On wine I achieve this by adding a new path to the value of PATH key stored inHKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment by creating path.reg file:
REGEDIT4
[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment]
"PATH"="{put old value of %PATH% here};C:\\path\\to\\python\\dll"
and running regedit path.reg, but I guess HKEY_LOCAL_MACHINE is a bit of overkill and you need something under HKEY_CURRENT_USER. I am using it with wine (windows emulator) anyway so I do not care. You can launch regedit without arguments and try to find something there.
AFAIR there is a way to set %PATH% in a link file you use to launch vim.
Maybe just putting the following into the vimrc will work:
let $PATH.=';C:\path\to\python\dll'
Note: none of the advices will work if vim was compiled with different python version support. Also if some configure flags (e.g. debugging support) differ between python from anaconda installer and python used by the whoever compiled vim error message should change. I do not know whether error message will change if vim is 32-bit and your python is 64-bit, but loading python will for sure fail in this case.
Your troubleshooting output shows that your Vim is compiled with dynamically loaded Python (+python/dyn), but the error you get and has('python') == 0 means that the Python interpreter cannot be successfully loaded. The IPython plugin probably has a guard clause that prevents its loading unless Python is available.
You need to fix the Python integration into Vim, either by making that DLL available to Vim (so that there'll be no errors and has('python') == 1), or (as a last resort) compiling Vim yourself.

pygame import error in eclipse

when I import pygame using eclipse on my mac, there's a import error:
However, I can still run this program correctly, So what can I do to fix it?
to quick fix you can do:
PyDev Package Explorer>right click your project>properties>PyDev - PYTHONPATH>External Libraries>Add source folder>PythonX.X(version where you installed pygame)/Lib/site-packages/pygame
this will include one external library for this project, but you should check if you are working with the right python version you installed.
I have 3 versions of python, pygame is only on Python2.6, so all my new projects that use pygame must have python2.6 syntax and interpreter python26.
To check your interpreter settings:
Window(menu)>Preferences>PyDev>Interpreter - Python>New>interpreter name you can put anything you may remember, interpreter executable find the python.exe and put the path there, OK.
Now you have added the entry for the interpreter, if you look down in the same window, into Libraries you can add many packages you want the interpreter to look for to resolve names and syntax.
They make Pygame for every version of Python. I have it for Python 3.4 it came out in March 2014. If you are getting the error there is no module named Pygame. It is because Pygame is not in Python's path or you have the wrong version of Pygame for your current version of Python. You can find more Pygame downloads here that arnt on pygame.org. Click on the blue word Pygame at the top and it will take you to the proper section of the page.
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Download the one you need for your Python version. If you hold the mouse over it it should show more info about the version in a tiny pop up. I am on windows but it found the path by itself. I'm not sure if it will for mac.

Categories