I am working with some python program where I need to import mysql.connector. But I am facing ImportError: No module named connector. I already read answers on same issue and also explore google to find out and try some step to fix still it not fixed.
I am working on MacOS. and I guess by default python 2.7.18 is installed and also I installed python 3.8.9.
So I came to know that I have to install pip install mysql-connector for python 2.X but when I ran this in my terminal it is showing command not found: pip . Then I tried to install pip3 install mysql-connector. for python3 and it got successfully installed.
But Still problem not fixed. Any idea how to fix this?
It could be the case where you are running the Python file with the wrong Python installation. In VS Code we can choose the interpreter using which we want to run our Python file.
By default, the Python extension looks for and uses the first Python
interpreter it finds in the system path. To select a specific
environment, use the Python: Select Interpreter command from the
Command Palette (Ctrl+Shift+P).
Just choose Python 3.8.9 from the list of interpreters. For complete guide you can refer to the documentation:
https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment
You got two Python installed in your system. Python3 and Python2.
Pip3 is just for python3.
You must use pip2 or pip2.7 for work with python2.
Search if you got the pip2 package installed is not then install it.
Related
I'm trying to install packages on multiple versions of Python. I'm currently running 3.8.8, and 3.11.0.
Following this post Install a module using pip for specific python version
called
python3.11 -m pip install pandas
which results in
File "<stdin>", line 1 python3.11 -m pip install pandas SyntaxError: invalid syntax
This seems to indicate an issue with python, so I double checked that python3.11 is installed.
the python3.11 works in isolation seems to work.
I don't understand why the install command isn't working.
If you’re using Linux try just
python3 —-version
In Windows you may need to add path to folder with installed Python to PATH variable.
Check your environment variables, you could try removing the variables pointing to the 3.8 version until you get the packages you want installed.
You could also try navigating to that python 3.11 installation directly, and executing the python shell from there, then run the command.
I am using Python 3.9 on Windows 10 which I downloaded directly from the Microsoft Store.
I tried running a script in PowerShell: Bash *.sh
This script is supposed to tell my computer to execute a .py script which uses scipy.io and many other modules.
Then I received this error:
ModuleNotFoundError: No module named 'scipy'
My strategy was to make sure pip was up to date, then use it to install the desired packages, then run some commands to see if the packages were installed.
I ran this command to update pip:
python3 -m pip install --upgrade pip
I ran this command to get some modules:
python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
I also tried this command just in case:
pip install scipy
and got the result:
Requirement already satisfied ...
I ran the command pip list to make sure scipy was in the list (and it was there).
Then I ran the command python and my prompt changed to ">>>" and entered import scipy and did not receive any errors.
I am very confused as to how I have scipy installed yet have my script tell me it isn't there. Please help!
From what you have posted it looks like you have more than one python environment path in your system, because of which when you are installing these libraries they are installed at certain location while when you run the bash script it is using some other python location.
Try using these commands in both your terminal (cmd in windows) as well as in you bash script:
import sys
print(sys.path)
This will give you the python environment path (location where your python libraries are present), then compare both the path you get from your terminal as well as bash. Add the path you got from the terminal to your global environment in order to make sure the same python version is used everywhere.
You can also refer to this: Python modules not found over terminal but on python shell, Linux
I had the same issue. You might have multiple versions of python and you only installed scipy on the one you are not using
OR
you are using an IDE which has the option to use packages you install that are not by default in python. Pycharm has that. When you make a new project, it has a tick option saying "Inherit global site-packages" which means it will use additional packages you have installed any.
Is there any ways install packages for python2 only?
I am using the latest Kali Linux version and I want to use some old scripts
At that moment of creating these scripts (Around years 2013-2015). The script was written in Python1 or Python2 and required me to install other packages such as "dns-python"
I did try to install these packages but I had some problems as the follow:
The script is already installed and automatically patched with latest python3 (not python2)
If I run python/ python2 to the script. It got error such as "ImportError: No module named 'dns'" (even I already installed this module successfully but it only patch to Python3)
If I run python3 to the script. It got some error such as the syntax is not correct (For example, the old python version using print command without "", or when you assign value, you will use "is", instead of using "==")
So the question is how to install packages for python2 only
I am not counting the way you roll back old Kali version
I am getting ImportError : no module named 'requests'.
But I have installed the requests package using the command pip install requests.
On running the command pip freeze in the command prompt, the result is
requests==2.7.0
So why is this sort of error happening while running the python file?
Run in command prompt.
pip list
Check what version you have installed on your system if you have an old version.
Try to uninstall the package...
pip uninstall requests
Try after to install it:
pip install requests
You can also test if pip does not do the job.
easy_install requests
I had this error before when I was executing a python3 script, after this:
sudo pip3 install requests
the problem solved, If you are using python3, give a shot.
One possible reason is that you have multiple python executables in your environment, for example 2.6.x, 2.7.x or virtaulenv. You might install the package into one of them and run your script with another.
Type python in the prompt, and press the tab key to see what versions of Python in your environment.
In Windows it worked for me only after trying the following:
1. Open cmd inside the folder where "requests" is unpacked. (CTRL+SHIFT+right mouse click, choose the appropriate popup menu item)
2. (Here is the path to your pip3.exe)\pip3.exe install requests
Done
if it works when you do :
python
>>> import requests
then it might be a mismatch between a previous version of python on your computer and the one you are trying to use
in that case : check the location of your working python:
which python
And get sure it is matching the first line in your python code
#!<path_from_which_python_command>
Opening CMD in the location of the already installed request folder and running "pip install requests" worked for me. I am using two different versions of Python.
I think this works because requests is now installed outside my virtual environment. Haven't checked but just thought I'd write this in, in case anyone else is going crazy searching on Google.
I am currently trying to run Pydev with Pymongo on an Python3.3 Interpreter.
My problem is, I am not able to get it working :-/
First of all I installed Eclipse with Pydev.
Afterwards I tried installing pip to download my Pymongo-Module.
Problem is: it always installs pip for the default 2.7 Version.
I read that you shouldn't change the default system Interpreter (running on Lubuntu 13.04 32-Bit) so I tried to install a second Python3.3 and run it in an virtual environement, but I can't find any detailed Information on how to use everything on my specific problem.
Maybe there is someone out there, that uses a similar configuration and can help me out to get everything running (in a simple way) ?
Thanks in advance,
Eric
You can install packages for a specific version of Python, all you need to do is specify the version of Python you want use from the command-line; e.g. Python2.7 or Python3.
Examples
Python3 pip your_package
Python3 easy_install your_package.