Installting psycopg2 package for python 3.5 on unix - python

I am trying to install package psycopg2 to connect with postgres database but getting below error on running this command
python3.5 /usr/local/bin/psycopg2-2.7.3.2/setup.py install
*running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/psycopg
gcc*** command here
In file included from psycopg/psycopgmodule.c:27:
./psycopg/psycopg.h:30:2: error: #error "Psycopg requires PostgreSQL client library (libpq) >= 9.1"*
Current environment already have python 2.4, we installed another version 3.5. Now both versions are present.
Since there no direct connectivity with external net, I got the file for psycopg2 package and installing using setup.py
Please suggest, what I am missing here and how can I resolve this.
Note that cannot connect to internet as this is a close environment so cannot use PIP for installation of package. My main aim is to connect to postgres database.

The key here is
Psycopg requires PostgreSQL client library (libpq) >= 9.1
Make sure that the first pg_config on your PATH is from PostgreSQL version 9.1 or higher.
From the documentation:
Psycopg is a C wrapper around the libpq PostgreSQL client library. To install it from sources you will need:
The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version

Related

Import ldap in python gives gives "DLL load failed" error

I'm using the "import ldap" in a python code. This is on a windows 10 machine.
I installed the python-ldap module
pip3 install python-ldap
Installed the dependencies based on the instructions at Python Can't install packages
Also resolved all the pip deployment issues based on Installing python-ldap in a virtualenv on Windows
I'm now getting the following error when executing the import ldap statement. am I missing something here? Any ideas to resolve it?
thon39\site-packages\ldap\__init__.py", line 34, in <module>
import _ldap
ImportError: DLL load failed while importing _ldap: The specified module could not be found.
Visit the unofficial Python binaries page:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap
Download the appropriate WHL package for your system.
For example, if you're using Python 3.8 on an x64 system, download python_ldap‑3.3.1‑cp38‑cp38‑win_amd64.whl
(hint: do NOT download the +sasl version unless you have the Cyrus SASL code running on your system...)
Start the VirtualEnv for your project, if you're using one (C:\Users\youruser\.virtualenv\YourVirtualEnv\Scripts\activate.bat) -- if you're not, skip this step.
Then run pip3 install C:\Path\To\python_ldap_x.x.x-cpXX-cpXX-winXX.whl and this should install the Python DLL (pyd) file for you.

pip install mysql-python fails with missing config-win.h

The python command is pip install mysql-python
The full error is _mysql.c(42): fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
Can someone please tell me how to fix this error?
What exactly is mysql-python and how is it different from regular mysql?
Another stack overflow post suggested installing it with a setup executable, where can I find this?
I installed something called mysql python connector from here:
https://downloads.mysql.com/archives/c-c/
It installed into C:\Program Files\MySQL\MySQL Connector C 6.1
However, I cannot find mysqld executable anywhere in this folder
Does this install mysql or do I actually need to install it from the Oracle website?
This required the full MySql server installation from Oracle
mysql-python is a module built for python-2 for interfacing with the mysql server so this does not include the mysql server and there is a fork of the same module called mysqlclient for python-3.
The reason for your error is you haven't installed Visual Studio 2019 to compile the c/c++ code in the python package. If you don't want to install Visual Studio 2019 check out these Python Wheel (.whl) files according to your python version
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python (Python 2)
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient (Python 3)

django Failed to build mysqlclient [duplicate]

I want to install MySqlclient on my windows system. I am Currently using Python 3.6. After going through the various post over Stackoverflow, I could Not find the correct way.
This is what I have done so far:
1) Installation by using pip pip install mysqlclient. Error:
Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools" http://landinghub.visualstudio.com/visual-cpp-build-tools
I already have Microsoft Visual C++ installed on my laptop. Some are saying you need 2015 edition.
2) Installation by using wheel file pip install mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl. Error:
Requirement mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl looks like a filename, but the file does not exist.
mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
2.1) Changing the whl file to different version pip install mysqlclient-1.3.13-cp36-cp36m-win32.whl. Error:
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\Foxtrot\\Desktop\\finaltest\\mysqlclient-1.3.13-cp36-cp36m-win32.whl'
Other things that are done: updated setuptools, updated wheel.
Had the same problem, searched the web etc. Here this answer:
mysql-python install error: Cannot open include file 'config-win.h'
It has all the instructions. In short go to this site: https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient:
At that website you will find
mysqlclient‑1.3.13‑cp36‑cp36m‑win32.whl
mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl
Download the correct file for your platform.
Then use your downloaded wheels file with pip and you're done:
pip install c:\mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl
The https://www.lfd.uci.edu/~gohlke/pythonlibs has lots of lots of compiled libraries to solve the problem of building them from source yourself. They even compile them for python 3.7 :)
Alternative Solution
You can also download Visual C++ Build Tools and then you should be able to install every (at least to my knowledge) version of mysqlclient with pip.
To do this go to this site: https://www.scivision.co/python-windows-visual-c++-14-required/ there you can find out which version of Build Tools you need and you can also find a link to download the installer. Be aware though Build Tools require more than 4GB of free disk space.
Tell pip not to use sources and use binary packages instead:
pip install --only-binary :all: mysqlclient
https://pip.pypa.io/en/stable/reference/pip_install/#install-only-binary
I can't find mysqlclient-1.3.13's whl file on PyPi. So you need to compile it from source. Unfortunately it's not easy. I'm not Windows guy, so I only can recommend guide like this
I am using python3.7 on Windows 10 operating system.
I had same issue and after a long research I had installed it successfully.
Install "Microsoft Visual C++ Build Tools"
AND
My OS is having 64 bit operating system but still then it need to install 32 bit version
"mysqlclient‑1.4.2‑cp37‑cp37m‑win32.whl"
Download binary wheels from "https://www.lfd.uci.edu/~gohlke/pythonlibs/" and run command
pip install [path_to_downloaded_file] eg: C:\Users\Ds\mysqlclient-1.4.2-cp37-cp37m-win32.whl
use pipenv instead of pip if you are using virtual environment.
The error means that the package has not yet been compiled for your versions of OS and Python. So pip tries to build it from the source for you.
There are two possible solutions.
The first option is to install the most recent version of Microsoft Visual C++ Build Tools. Just go ahead and download it from the Microsoft website. Then pip should be able to compile the package.
Another option is using an unofficial binary. As mentioned here, a resource proved to be useful is https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python . Just download the pre-compiled package and install it using
pip install c:\path-to-a-pre-compiled-package
Had the same problem just day.
Tried to install mysqlclient on a Windows Server R2.
[...]
Tl;dr
"MySQL Connector C 6.1" was installed in the wrong directory: "C:\Program Files\MySQL" instead of "C:\Program Files (x86)\MySQL" where it should be for me.
--> Copied "MySQL Connector C 6.1" to "C:\Program Files (x86)\MySQL" Directory.
"C:\Users\MoBoo\AppData\Local\Temp" was Read-Only: Therefore pip couldn't compile files into Temp dir.
--> Allow Write access to "C:\Users\MoBoo\AppData\Local\Temp" Directory.
Here is what worked for me. I uninstalled mysql and re-installed it.
pip uninstall mysqlclient
Then simply re-install, so it picked the current version "1.4.2.post1"
pip install mysqlclient
Which interestingly, works straightaway.
for this error, most of user's suggest to install vs build but there is an alternative which works perfectly in my case and is sure for you too.
Download latest MySQL client from here
mysqlclients
Here you can see many version but prefer to download the latest one which has 32 bit and 64-bit files.
download theme and past the file on your projects root folder then run the same command but with the full file name of downloaded mysqlclient.
like: pip install mysqlclient‑1.4.6‑cp38‑cp38‑win32.whl
in my case, the file is this
also if have already the XAMPP server then you can use its PHPMyAdmin with python.
You just need to change on your roots setting.py file for this.
Something like this
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydjango',
'USER': 'root',
'PASSWORD':'',
'HOST':'localhost',
'PORT':'3306',
}
}
The port is the same which you see on xampp panel just before the start button of MySQL.
After changing this you just again start your server by hitting this command
python manage.py runserver
If you didn't see any error then congratulations you successfully connected with MySQL database.
Enjoy...
The easiest way to solve this problem is to download the correct version of MySQL client that supports the python version installed on your system.
MYSQLclient download link: https://pypi.org/project/mysqlclient/#files
Check the python version installed in your PC:
I was using Python version 3.7 and the same error was happening.
After trying all the possibilities, simply reinstalling the newest Python version (3.10.7 in my case) solved the issue.

Error with simplejson dependency when installing Eve

I am new to Python and am trying to install Eve. I have Python 3.6.3 installed and am using pipenv. When I run pipenv install eve it fails with the error (here's an excerpt):
running build_ext
building 'simplejson._speedups' extension
error: [WinError 3] The system cannot find the path specified: 'C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1\\lib'
_______________________________________
Error: An error occurred while installing eve!
Failed building wheel for simplejson
From what I can tell, this path is for the Windows 8.1 SDK.
What can I do to fix this? Do I need to install this SDK in order for simplejson to work? I don't really want to install this SDK, so why does simplejson need this?
I suspect that I don't actually need this SDK as I assume all of this can normally be executed in a Linux environment. Why would this dependency exist when executing on a Windows 7 machine as I am trying to do?
I found the answer. Yes, I do need the SDK. Windows compilers are required to "Install a non-pure Python package from sources with Pip" on Windows machines and are included in Microsoft Build Tools. More information can be found here: https://wiki.python.org/moin/WindowsCompilers

Is there a prebuilt version of python 2.7 mySql db APIs to install and use with django or do i have to really build it from scratch?

i want to install django and use mysql as the backend.
i installed django and it worked fine. i am now following the first tutorial and created mysite.
After putting the mysql backend into into the settings.py, the web server no longer ran. I get the following error:
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
i already have a mysql instance setup on a remote machine. i changed the settings.py file with my db info but following to install and the initial tutorial, it still seems to want me to install Python database API 2.0 interface for the MySQL 5.1 database.
the only links i see are to the source code.
Is there a prebuilt version of mysql for python libraries that work for python 2.7 and are built so i don't need C++ compilers, etc on my machine to get django setup.
For windows you might try the binary installer from http://www.codegood.com/archives/129
On linux you would normally install it using the native package manager, e.g. sudo apt-get install mysql-python or via sudo easy_install mysqld.
The easy_install way will also work on windows provided you have installed the right version of Visual Studio (2010?) or mingw.

Categories