I am new to Python and writing a lambda function.
I installed urllib3 using pip but still getting this following error.
I tried restarting vscode/ uninstall and reinstall but still getting the error.
this is the result when I run pip show urllib3
what am i missing here?
You need to make sure that VS Code uses the same Python Interpreter that you installed this package to.
You can see it here:
Looks like yours should point to
c:\user\###\appdata\local\programs\python\python39\bin\python
(or something like that, where your python executable file is located)
Maybe there is more than one python environment on your machine, And the location where you installed the package is inconsistent with the python interpreter you are using now.
You can use CTRL + SHIFT + P to open the command palette and search Python: Select Interpreter (or click on the interpreter version displayed in the lower right corner).
Select the environment interpreter where you have the urllib3 package installed.
Related
I'm having ImportError: cannot import name 'Literal' from 'typing' error message when I try to use pip install. Anyone can help?
The problem is with the configuration of your environmental variables. The first thing, I'd suggest you do is uninstall all the unused versions of python. To my mind, the latest of python 3.x.x series is the best.
Steps:
The easiest way of accessing it is just to type environment variable in Windows 10 search bar. (Assuming you are using Windows 10)
Then follow these:
At the bottom half part of the subsequent window search for path:
If you double click that, look for python. Make sure you have such paths added there and you need to have a compatible version of python. Usually, your python bin directory is located in Program Files.
there is some modules that when im trying to install from pypI, like pyfiglet or Django framework, i'll saw some errors. how can i fix it? my python versio is 3.9.4
For installing and checking the python module "pyfiglet" in VS Code, please refer to the following:
Please make sure that python is available, and select the required python environment in the lower left corner of VS Code.
Please use the shortcut key Ctrl+Shift+` to open a new VS Code terminal, and check whether the python used by the terminal is the same as the lower left corner of VS Code: ( python --version )
Then install the module "pyfiglet": (pip install pyfiglet)
Check the installation of this module: (pip show pyfiglet)
Run:
Reference: Getting Started with Python in VS Code and Python environments in VS Code.
I have downloaded Pandas library with pip install pandas through the command prompt, when I try to import pandas as pd PyCharm returns an error : ModuleNotFoundError: No module named 'pandas'
I have tried to uninstall and install again many times but nothing seems to work. Does anybody know a solution to this?
You can try downloading the library from PyCharm settings:
File -> Settings
then, Project: -> Python Interpreter
Click a + sign to the right,
Search for the pandas library,
and finally, press 'Install Package'
I think you have to choose the right python interpreter. Check my screenshot
You likely have multiple copies of Python installed on your system. PyCharm can be configured to use any version of Python on your system, including any virtual environments you've defined. The solution is to match up the version of Python you've installed Pandas into with the version of Python that PyCharm is using to run your code.
There are two places where you specify a Python version. First of all, your Project has a version associated with it. Check the "Python Interpreter" section of the "Project" section of your Preferences for that. That version is used for syntax highlighting, code completion, etc.
By default, the abovementioned Python version will also be used to run your code. But you can change the version of Python that your code is run with by creating or modifying a Run Configuration. To do this, check the menu next to the Run and Debug toolbar buttons near the top-left of your PyCharm window.
When you do get into the Python Interpreter section of the Preferences, you'll find that you can see all of the modules installed for each Python version that PyCharm knows about. You can use this to check to see if Pandas is installed for a particular Python version.
I would suggest you get comfortable with all that I've said above. It will save you many headaches in the future.
Here is the error
import numpy
Exception has occurred: ModuleNotFoundError
No module named 'numpy'
File "C:\path\to\file\32.py", line 1, in <module>
import numpy
Let me know how did you install the NumPy package; using pip or something else?
If you have multiple python versions, i.e. 2.x and 3.x at the same time, please make sure your interpreter for the 32.py file is the version that you installed NumPy on.
To possibly fix your problem, you should first try installing it and see if there are any errors. You should also check the version of Python you are running on Windows 10, because when you update Python it sometimes switches names between py and python
As you can see, the version of Python has changed between py and python so you should try changing that first.
If this does not work, you should try finding the directory for NumPy and adding it to the system PATH in your script. The installer usually shows you the location by doing the following:
import sys
sys.path.append("<insert numpy location here>")
import NumPy
This should manually force it into finding the package. If none of this works, please tell us and we should be able to find a different solution.
Happy Coding!
If you're using a code editor like PyCharm, you could install it by clicking on
file then settings then the project interpreter setting and install new module! You can search for the module and install.
Make sure that the python version that you want to use is a Windows Environmental Variable. You can test this by running this line in your command line.
> python --version
If you get some other python version that is not the one that you wish to use you can set the python version you want by finding where exactly your Python folder is located and go into settings and set the path as a new variable (I can leave a tutorial for you). If that is too much of a hassle, the Python installers can set the python that you will install as an environmental variable for you. (You could uninstall and reinstall and make sure that you allow it to make it an environmental variable.
After that you should be able to import whatever external packages you want using pip
for example:
pip install numpy
I have successfully installed mysql-connector using pip.
Installing collected packages: mysql-connector
Running setup.py install for mysql-connector ... done
Successfully installed mysql-connector-2.1.6
However, in PyCharm when I have a script that uses the line:
import mysql-connector
PyCharm gives me an error saying there isn't a package called "mysql" installed. Is there some sort of syntax that should be used to indicate that the entire package name contains the "-" and is not just "mysql"?
When I run my script in IDLE, mysql.connector imports just fine. (I changed it to mysql-connector after seeing the "-" in the name of the package and having trouble in PyCharm.)
EDIT: per #FlyingTeller's suggestions, in the terminal, "where python" returns C:...Programs\Python\Python36-32\python.exe. "where pip" returns ...Python\Python36-32\Scripts\pip.exe. The interpreter in PyCharm for this project is this same filepath & exe as "where python" in the terminal.
Per #Tushar's comment, this program isn't using a virtual environment and the mysql-connector library is already present in the Preferences->Project->Python Interpreter.
Thanks for the feedback and any additional guidance you may be able to provide.
You need to import the connector as
import mysql.connector
Check the examples in the docs for this
If that doesn't work, then there might be an inconsistency between the interpreter that pycharm uses and the one you installed the package for. In pycharm, go to
File->Settings->Project Interpreter
In the terminal, enter
where python #Windows
which python #Linux
and also
where/which pip
make sure that the interpreter configured in pycharm is the same that appears when typing which/where python in the command line/shell. Also make sure that pip also points to the same python distribution.
It may be because you are using a virtual environment inside pyCharm, while you might have installed the library using system's default pip.
Check Preferences->Project->Python Interpreter inside Pycharm, and see if your library is listed there. If not, install it using + icon. Normally, if you use pyCharm's inbuilt terminal, it is already using the same virtual env as your project. So using pip there may help.
Usage syntax is as below:
import mysql.connector
conn = mysql.connector.connect(
user='root',
password='#####',
host='127.0.0.1',
database='some_db')
conn.close()
Go to project interpreter and download mysql-connector.You need to install it also in pycharm
I was having this exact issue as well, after a while i solved it by simply changing the name of my script in PyCharm, turns out i had named my script mysql.py (because it was my first time attempting to connect it to python) and it was critically interfering with the import.
TLDR: Change the name file if it's asssigned as mysql.py, as it takes priority over the mysql-connector and prevents it from being imported, even if installed correctly.
People have commented with reasonable responses (and I'm sure OP is good on this by now) but they weren't super clear to me...
Don't use "pip3 install" in terminal in your pycharm project. In fact, uninstall any mysql connectors you have already using this method.
So now that you have verified there are no other mysql connector packages... Add the package "mysql-connector-python" using the Python Interpreter only (in preferences) in your pycharm project. Now the package should work!