I simply want to use the MySQL driver for python:
import mysql.connector
Note that I've tried most of the suggestions on this old post, and they still aren't working after troubleshooting the pip install (by upgrading pip in venv and installing wheel, etc.):
Can not get mysql-connector-python to install in virtualenv
I've tried both:
python3 -m pip install mysql-connector-python
...and...
python3 -m pip install mysql-connector-python-rf
...and while both now show no errors during the pip install process, I still have the error:
Unable to import mysql.connector
How do I determine what's going wrong and how do I fix? I receive no errors until "import mysql.connector", which seems like it should work fine.
In my case, the issue was apparently that I wasn't managing packages properly in the Virtual Environment.
I was using Visual Studio Code and here's how I resolved.
Nuke the project and recreate.
Add app.py file to my new folder.
Go to the debug tab and create a launch.json file (in my case configured for Flask).
Open the debug console and go to zsh terminal inside of Visual Studio Code.
Execute "python3 -m venv .venv"
Click "yes" when the prompt asks about using the workspace folder.
Execute "source .venv/bin/activate" to use the virtual environment.
"python3 -m pip install ..." to my heart's content.
More setup details here:
https://code.visualstudio.com/docs/python/environments#_global-virtual-and-conda-environments
Installed python installed on system of version 3.8.5 but there is an error with pip. pip is not installed
Below is the path
C:\Users\Comp1\AppData\Local\Programs\Python\Python38-32\Scripts
Found some results and tried running python get-pip.py from cmd but didn't work.
Also checked PATH and was correct
After using pip command in cmd it gives "pip is not recoganized"
Please let me know how can I fix this issue.
I just upgraded to python 3.7 and I realized that all my modules stuck with the previous version. Even Django is not recognised anymore. How can I do to transfer everything to the new version? I am a little lost right now, don't even know where the new version has been installed.
Edit:
When I do $ which python3.6 the terminal tells me it doesn't exist, but I have a python3.6 directory in /usr/local/lib/, where all modules are installed.
In the same directory /usr/local/lib/ I also have a python3.7 directory with some modules installed but many are missing. However when I search for the file python3.7 in my finder it doesn't appear. when I do $ which python3.7 the path is /usr/local/bin so not the same path as the directory.
Anyone sees what happened and knows how I can transfer all modules to python3.7?
Even if the old python version has been removed, it is possible to use the pip of the current python version with the --path option to list all the modules installed in the previous version.
For example, migrating all my user installed python modules from 3.7 to 3.8
pip freeze --path ~/.local/lib/python3.7/site-packages > requirements.txt
pip install --user -r requirements.txt
Incidentally, I always use pip install with --user and leave the system wide installations to the package manager of my linux distro.
It is safer to re-install all packages due to possible compatibility issues:
pip3.6 list | awk '{print $1}' | xargs -I{} pip3.7 install {}
in older version of Python --run the command
pip freeze > requirements.txt
download and install newer version on python.. change the PATH variable to the new version
and run the command
pip install -r requirements.txt
I'm not sure about all modules...but if you want to install a module specifically in python3.7, try this:
python3.7 -m pip install *module_name*
In some cases, we don't have the opportunity to pip freeze in old version--because I've already updated and old version have been purged! There are some measures I've taken to recover some of the packages but I'm NOT sure every package would work with this fix.(e.g. the packages built with wheels)
mv /your/path/to/python3.{6,7}/site-packages/
If the case is packages installed outside venv (in /usr/local/ or ~/.local), reinstall pip with get-pip.py, just to be safe.
If you are recovering a virtualenv. Activate your virtualenv and use my script
Most of your packages should work by now. If anything malfunctions, pip reinstall would works. If you still want it 100% works, pip freeze now.😉
I have an alternative
(Not sure if works outside Windows 10)
I'm currently migrating from 3.7 to 3.8 and the way I found to re-install my previous libraries was by using a script I had that updates all packages via pip install. (Assuming you installed your new Python version as your main version) This checks for all the packages I had and updates/install them in the new Python version.
Note: I prefer to run the script from the command line
Use the file explorer to go to the folder where you have the script;
Click on the path box, write "cmd" and press enter to open a command line from the folder where you are;
Write "python name_of_your_script.py" and press enter to run the command.
The script (adapted from this solution):
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
[call("pip install " + name + " --upgrade") for name in packages]
I faced a similar problem, now that I upgraded from python 3.7 to python 3.8 (new)
I installed Python 3.8, but the system kept the python37 subfolder with the already installed packages(...\Python37-32\Lib\site-packages) even with the Pyhton38 subfolder created, with the new python.exe.
Usually, it's possible to keep on using the old libraries on your new Python version, because the existent libraries installation folder are already registered in your local computer system path (*).
Even though, I've had problems to use some libraries (some worked in Jupyter Notebook but not in Spyder). I tried the alternatives others proposed to migrate libraries but it did not worked (maybe I did not
So I used brutal force solution.. Not elegant at all, but it worked:
remove the OLD python version folders from the system path or even remove the folder itself for good..
Folders: C:\Users\USERNAME\AppData\Roaming\Python\Python37
C:\Users\USERNAME\AppData\Local\Programs\Python\Python37
Reinstall the packages you need, preferably via Anaconda prompt.
python -mpip install library_name
OR
pip install --user --force-reinstall package_name
OR
pip install --user --force-reinstall package_name == specify_package_version
The libraries will be installed at c:\users\USERNAME\anaconda3\lib\site-packages and recognized by your new python version.
(*) to add the folder to the PATH: System properties --> environment variables --> click "Path"--> edit --> add folder name)
I have tried to install libraries using pip but my console doesnt recognize as a command. I checked the python/scripts folder and there was no ppip.exe in the folder. I reinstalled Python 3.6 a couple of times but I havent been able to use it. I tried it on another computer and pip installed itself with python 3.6.
I've seen answers that say to open a Python shell, then insert
python -m pip install 'packagename'
but i tried this and the shell marked invalid syntax at the end of writing pip
on linux(ubuntu)
#for default
sudo apt install python-pip
#for version specific
python2.7
sudo apt install python2-pip
for 3.x
sudo apt install python3-pip
for windows
In some terminals try to use
$py -m pip install packagename
Of course you first have to import pip with
$import pip
if pip is installed the following will work for sure
open a python shell then
import pip
pip.main(['install', 'packagename'])
replace the packagename with the package you want to install
because of the path problem try to use absolute paths ( in windows beginning with drive letter i.e. C:/.../.../pip.exe). in batch script it is generally good idea to use absolute paths. Alternatively check if your path has to be fixed : https://docs.python.org/3/using/windows.html
( http://jelly.codes/articles/python-pip-module/ )
Operating systems search for executables in the system path. I.e. windows knows by default where its own executables are located because the directory is in the system path, however when new software is installed that contains executables like pip the system path has to be edited to inform windows ( or linux ) where the new executables are located. The path is an environment variable. This is also valid for other languages and programs like java ( Environment variables for java installation ) ,...
Now your problem very likely is that the directory where the pip.exe executable is stored is not part of your windows path. This has to be fixed like in https://docs.python.org/3/using/windows.html, chapter 3.3. Configuring Python
How to run Pip commands from CMD
I'd just installed the scrapyd-client(1.1.0) in a virtualenv, and run command 'scrapyd-deploy' successfully, but when I run 'scrapyd-client', the terminal said: command not found: scrapyd-client.
According to the readme file(https://github.com/scrapy/scrapyd-client), there should be a 'scrapyd-client' command.
I had checked the path '/lib/python2.7/site-packages/scrapyd-client', only 'scrapyd-deploy' in the folder.
Is the command 'scrapyd-client' being removed for now?
Create a fresh environment and install scrapyd-client first using below
pip install git+https://github.com/scrapy/scrapyd-client
And it should work. I was able to get it
$ which scrapyd-client
/Users/tarun.lalwani/.virtualenvs/sclient/bin/scrapyd-client
The package on pip may not be the latest one