adbyits
asked on
getting error when iusing pip3 install mysql
Hi all i am trying to setup my ubuntu server so i can run my python scripts and when i try to install mysql-client or mysql for python i am getting a error
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pi p-build-nw k7rejx/mys qlclient/s etup.py';f =getattr(t okenize, 'open', open)(__file__);code=f.rea d().replac e('\r\n', '\n');f.close();exec(compi le(code, __file__, 'exec'))" install --record /tmp/pip-10shw23u-record/i nstall-rec ord.txt --single-version-externall y-managed --compile" failed with error code 1 in /tmp/pip-build-nwk7rejx/my sqlclient/
i have tried good old google and all the ones i have found on there to try didnt work any help would be great
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pi
i have tried good old google and all the ones i have found on there to try didnt work any help would be great
Take a look if my solution solves it for you
ASKER
The directory '/home/ADBY/.cache/pip/htt p' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ADBY/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting mysqlclient
Downloading https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz (85kB)
11% |███▉ | 10kB 33.2MB/s eta 0:00: 23% |███████▋ | 20kB 21.6MB/s eta 0:00: 35% |███████████▌ | 30kB 25.3MB/s eta 0:00: 47% |███████████████▎ | 40kB 9.9MB/s eta 0:00:0 59% |███████████████████▏ | 51kB 11.4MB/s eta 0:00: 71% |███████████████████████ | 61kB 13.1MB/s eta 0:00: 83% |█████████████████████████ █▉ | 71kB 14.2MB/s eta 0:00: 95% |█████████████████████████ █████▋ | 81kB 15.5MB/s eta 0:00: 100% |█████████████████████████ ███████| 92kB 8.0MB/s
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pi p-build-nw k7rejx/mys qlclient/s etup.py';f =getattr(t okenize, 'open', open)(__file__);code=f.rea d().replac e('\r\n', '\n');f.close();exec(compi le(code, __file__, 'exec'))" install --record /tmp/pip-10shw23u-record/i nstall-rec ord.txt --single-version-externall y-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6 /MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6 /MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.6 /MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6 /MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6 /MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6 /MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6 /MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6 /MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6 /MySQLdb
creating build/lib.linux-x86_64-3.6 /MySQLdb/c onstants
copying MySQLdb/constants/__init__ .py -> build/lib.linux-x86_64-3.6 /MySQLdb/c onstants
copying MySQLdb/constants/CLIENT.p y -> build/lib.linux-x86_64-3.6 /MySQLdb/c onstants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6 /MySQLdb/c onstants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6 /MySQLdb/c onstants
copying MySQLdb/constants/FIELD_TY PE.py -> build/lib.linux-x86_64-3.6 /MySQLdb/c onstants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6 /MySQLdb/c onstants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.linux-x86_64-3. 6
creating build/temp.linux-x86_64-3. 6/MySQLdb
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,4,6,'fin al',0) -D__version__=1.4.6 -I/usr/include/mysql -I/usr/include/python3.6m -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3. 6/MySQLdb/ _mysql.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3. 6/MySQLdb/ _mysql.o -lmysqlclient -lpthread -lz -lm -lrt -latomic -lssl -lcrypto -ldl -o build/lib.linux-x86_64-3.6 /MySQLdb/_ mysql.cpyt hon-36m-x8 6_64-linux -gnu.so
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
-------------------------- ---------- ----
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pi p-build-nw k7rejx/mys qlclient/s etup.py';f =getattr(t okenize, 'open', open)(__file__);code=f.rea d().replac e('\r\n', '\n');f.close();exec(compi le(code, __file__, 'exec'))" install --record /tmp/pip-10shw23u-record/i nstall-rec ord.txt --single-version-externall y-managed --compile" failed with error code 1 in /tmp/pip-build-nwk7rejx/my sqlclient/
ADBY@Flight-Check-Server:~ /
The directory '/home/ADBY/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting mysqlclient
Downloading https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz (85kB)
11% |███▉ | 10kB 33.2MB/s eta 0:00: 23% |███████▋ | 20kB 21.6MB/s eta 0:00: 35% |███████████▌ | 30kB 25.3MB/s eta 0:00: 47% |███████████████▎ | 40kB 9.9MB/s eta 0:00:0 59% |███████████████████▏ | 51kB 11.4MB/s eta 0:00: 71% |███████████████████████ | 61kB 13.1MB/s eta 0:00: 83% |█████████████████████████
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pi
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6
copying MySQLdb/constants/__init__
copying MySQLdb/constants/CLIENT.p
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6
copying MySQLdb/constants/FIELD_TY
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.linux-x86_64-3.
creating build/temp.linux-x86_64-3.
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,4,6,'fin
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
--------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pi
ADBY@Flight-Check-Server:~
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
OK just as info. about the root cause and some recommended strategies.
In general it is not a good idea to pip install packages with sudo. You might enter in conflict with the packages installed with apt / by your distribution and debugging strange problems will be very difficult from then on.
In general I recommend to create a virtualenv for each project and install packages in this env.
Apart from that.
The packages mysql-client / mysql are packages, that are written in C and have to be compiled during pip installation.
This compilation fails often if certain packages were not installed on your machine. This kind of error manifests itself most of the time by error messages complaining that a header file cannot be found. (e.g. ssl.h or something similiar) or during the linking phase. like "/usr/bin/ld: cannot find -lssl".
You might try installing following apt-packages before running pip install.
If the version of your linux distribution is good enough for you, then just look at following apt packages:
As general strategy I recommend to use apt install for your system python and use pip install only for virutalenvs ( https://virtualenv.pypa.io/en/stable/ )
if you want to use python versions, that don't exist for your ubuntu version, then look also at pyenv ( https://github.com/pyenv/pyenv ) which can be (if you want also combined with virtualenv
In general it is not a good idea to pip install packages with sudo. You might enter in conflict with the packages installed with apt / by your distribution and debugging strange problems will be very difficult from then on.
In general I recommend to create a virtualenv for each project and install packages in this env.
Apart from that.
The packages mysql-client / mysql are packages, that are written in C and have to be compiled during pip installation.
This compilation fails often if certain packages were not installed on your machine. This kind of error manifests itself most of the time by error messages complaining that a header file cannot be found. (e.g. ssl.h or something similiar) or during the linking phase. like "/usr/bin/ld: cannot find -lssl".
You might try installing following apt-packages before running pip install.
sudo apt-get install python-pip python-dev libmysqlclient-dev libssl-dev libcrypto++-dev
If the version of your linux distribution is good enough for you, then just look at following apt packages:
python-mysqldb
python-pymysql
python-mysql.connector
python3-pymysql
python3-mysqldb
python3-mysql.connector
As general strategy I recommend to use apt install for your system python and use pip install only for virutalenvs ( https://virtualenv.pypa.io/en/stable/ )
if you want to use python versions, that don't exist for your ubuntu version, then look also at pyenv ( https://github.com/pyenv/pyenv ) which can be (if you want also combined with virtualenv
I would have expected some complaints about missing C/C++ header files.
Do you try installing in a virtualenv or in the default python? (It seems to be the system python)
I'd suggest to create a brand new virtualenv and try installing there and copy the entire error message.