On a Mac w/ Python2.6 and trying to install psycopg2 - python

I am new to Python. I have Python2.6 running now. I am following the Tutorial on the Python site. My question is when I try to follow the instructions here:
http://py-psycopg.darwinports.com/
I get something like...
sudo port install py-psycopg
... bunch of errors here...
Error: The following dependencies failed to build: py-mx python24
I am running MacOS X 10.4.
How do i make this work?
Any reply would be greatly appreciated.
UPDATE:
After running the code below I get the errors below:
$ sudo port install py26-psycopg2
Warning: Skipping upgrade since openssl 0.9.8k_0 >= openssl 0.9.8k_0, even though installed variants "" do not match "+darwin". Use 'upgrade --enforce-variants' to switch to the requested variants.
Warning: Skipping upgrade since readline 6.0.000_1 >= readline 6.0.000_1, even though installed variants "" do not match "+darwin". Use 'upgrade --enforce-variants' to switch to the requested variants.
---> Computing dependencies for py26-psycopg2
---> Building python26
Error: Target org.macports.build returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_python26/work/Python-2.6.2" && /usr/bin/make all MAKE="/usr/bin/make CC=/usr/bin/gcc-4.0" " returned error 2
Command output: /usr/bin/install -c -d -m 755 Python.framework/Versions/2.6
if test ""; then \
/usr/bin/gcc-4.0 -o Python.framework/Versions/2.6/Python -dynamiclib \
-isysroot "" \
-all_load libpython2.6.a -Wl,-single_module \
-install_name /opt/local/Library/Frameworks/Python.framework/Versions/2.6/Python \
-compatibility_version 2.6 \
-current_version 2.6; \
else \
/usr/bin/libtool -o Python.framework/Versions/2.6/Python -dynamic libpython2.6.a \
-lSystem -lSystemStubs -install_name /opt/local/Library/Frameworks/Python.framework/Versions/2.6/Python -compatibility_version 2.6 -current_version 2.6 ;\
fi
ld64 failed: in libpython2.6.a(__.SYMDEF), not a valid ppc64 mach-o file
/usr/bin/libtool: internal link edit command failed
make: *** [Python.framework/Versions/2.6/Python] Error 1
Error: The following dependencies failed to build: python26
Error: Status 1 encountered during processing.
FYI, the python i installed was the dmg file from the pythong site.
Thanks,
Wenbert

If you're using Python 2.6, you actually want to build py26-psycopg2:
$ sudo port install py26-psycopg2
In MacPorts, py-* packages build using Python 2.4, py25-* using Python 2.5, and py26-* use Python 2.6.

Maybe you need to look at the version for Python 2.6?

I had problems installing psycopg2 on my 10.4 Mac too. I installed both Python and Postgres from dmg files, and sudo easy_install psycopg2 was giving an error I can't remember now. What worked for me was an easy solution:
PATH=$PATH:/Library/PostgreSQL/8.3/bin/ sudo easy_install psycopg2
which I've found at http://blog.jonypawks.net/2008/06/20/installing-psycopg2-on-os-x/

I installed psycopg2 on my Mac with setuptools and easy_install. First get the Python 2.6 egg from the setuptools downloads page, then install it with the instructions on that page. Then you can run the following to install it:
sudo easy_install psycopg2
You may have different luck, but that's what did it for me.

I tried everything and nothing works. At least this post:
http://benkreeger.com/post/312303245/conquering-symbol-not-found-pqbackendpid
led me to homebrew which made it perfectly.

Related

Pyenv: Not able to install python 3.x version MacOS 12.3.1

I am not able to I have tried to install different version of python3.9.X (3.9.8, 3.9.9, 3.9.10, 3.9.11) and none of them are working.
I have also tried some 3.8.X and 3.5.X all giving different errors.
I will post the 3.9.8 log (the one I am interested on)
Platform information: MacOS Monterey 12.3.1
pyenv version: 2.2.5
Python version: 3.9.8
C Compiler information: Apple clang version 12.0.5 (clang-1205.0.22.9)
Command used in pyenv: pyenv install 3.9.8
This is my .zprofile (I am using oh-my-zsh)
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
I have also installed all the required dependencies
brew install openssl readline sqlite3 xz zlib
Here you can find the log and here you can find the config log
This is what I am getting:
# pyenv install 3.9.8
python-build: use openssl#1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.9.8.tar.xz...
-> https://www.python.org/ftp/python/3.9.8/Python-3.9.8.tar.xz
Installing Python-3.9.8...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
BUILD FAILED (OS X 12.2.1 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/jl/hp_s9knj13x5ft7mffr258r40000gp/T/python-build.20220412182145.25030
Results logged to /var/folders/jl/hp_s9knj13x5ft7mffr258r40000gp/T/python-build.20220412182145.25030.log
Last 10 log lines:
if test $? -ne 0 ; then \
echo "generate-posix-vars failed" ; \
rm -f ./pybuilddir.txt ; \
exit 1 ; \
fi
make: *** [Makefile:688: python.exe-gdb.py] Killed: 9
make: *** Waiting for unfinished jobs....
/bin/sh: line 5: 33970 Killed: 9 ./python.exe -E -S -m sysconfig --generate-posix-vars
generate-posix-vars failed
make: *** [Makefile:618: pybuilddir.txt] Error 1
I spent a couple of days with the issue and I found the answer on the GitHub Issues.
The problem was the antivirus as documented here.
Once the Antivirus was disabled everything was installed without any error (I tried python 3.9.8, 3.9.9, 3.9.10, 3.9.11). I had Apex One (Mac) Antivirus and uninstalling was not trivial.
This guide was helpful. I used Those two commands:
sudo launchctl unload /Library/LaunchDaemons/com.trendmicro.* /Library/LaunchAgents/com.trendmicro.*
sudo kill -9 $(pgrep iCoreService TmLoginMgr)
If you recieve this warning is completly fine
Warning: Expecting a LaunchDaemons path since the command was ran as root. Got LaunchAgents instead.
`launchctl bootout` is a recommended alternative.
/Library/LaunchAgents/com.trendmicro.TmLoginMgr.plist: Could not find specified service
Unload failed: 113: Could not find specified service
Just check your Icon on the top bar is gone. Additionally you can make sure this command does not return any process:
pgrep iCoreService TmLoginMgr MainUI

Installing hyperledger indy node code fails on python3 not being default on Mac

I am installing Hyperledger Indy (sovrin) self-identity software per these instructions.
I have Python2.7 installed via Anaconda 3. I also have Python3.6.3 installed that I downloaded and installed from here.
I'm trying to install some other software that has a dependency for Python > 3.5.
I've tried several methods to change my default Python:
Per this SO I set it manual in current terminal window:
alias python='python3'
Per same SO I vi .bash_profile and added:
alias python='python3'
then source ~/.bash_profile
Set a link to Python3:
bc-computer:~ momi$ unlink /usr/local/bin/python2
bc-computer:~ momi$ ln -s /usr/local/bin/python3 /usr/local/bin/python
but still continue to get the same error:
bc-computer:~ momi$ pip install indy-node-dev
Collecting indy-node-dev
Using cached indy-node-dev-1.2.227.tar.gz
Complete output from command python setup.py egg_info:
FAIL: Requires Python 3.5 or later, but setup.py was run using 2.7.14
NOTE: Installation failed. Run setup.py using python3
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3f/sh6dr8wx6w720b1_w38f_fh00000gq/T/pip-build-ecZnYY/indy-node-dev/
I also tried setting up a python3 test environment per this:
python3 setup.py test
And got this error:
> /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python:
> can't open file 'setup.py': [Errno 2] No such file or directory
Please note that I tried this suggestion which seems to be the non-duplicate answer but didn't work for me:
The safest way is to set an alias in ~/.bashrc:
alias python=python3
My environment:
uname -msra
Darwin bc-computer.local 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64
My OS:
High Sierra 10.13.1
which -a python
/Users/momi/anaconda2/bin/python
/usr/local/bin/python
/usr/bin/python
Thank you
Ok the solution was to use pip3 rather than pip for my install command per Mike Mueller's answer here:
pip3 install indy-node-dev
I assume that pip3 points to python3x rather than 2x.
I have also installed Hyperledger Indy SSI VC using MacOs Python 3.6.3. It is working for for me. I could demo the VON Network. It seems that your machine environment still points to Python 2.7. There are different ways by which we can point to Python 3.6.3 through virtual environment. You can try those options.

How to install libgpuarray and clBLAS in python on mac os x (10.9)?

I'm trying to install libgpuarray (http://deeplearning.net/software/libgpuarray/installation.html) for python on OSX 10.9. I installed CMake 3.0 and are using the UI. I downloaded the libgpuarray and clBLAS source from git and unpacked under Users/user/libgpuarray .. /clBLAS respectively.
Using CMake UI I get the following warning when generating the build:
MACOSX_RPATH is not specified for the following targets:
gpuarray (clBLAS respectively)
Executing 'python setup.py build' results in the following error:
/Users/i043337/Library/Python/2.7/lib/python/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning:
"Using deprecated NumPy API, disable it by " "#defining
NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
'#warning "Using deprecated NumPy API, disable it by " \
^
pygpu/gpuarray.c:354:10: fatal error: 'gpuarray/types.h' file not found
'#include "gpuarray/types.h"
Tried to figure out how to set the correct path but I'm lost to be honest.
Any help is more than appreciated!
Latest XCode (incl. DeveloperTools) installed. Python version is 2.7 from python.org and under the following paths (Terminal$ type -a python)
python is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
python is /usr/bin/python
python is /usr/local/bin/python
I solved this by running:
python setup.py build_ext -I /usr/local/include -L /usr/local/lib
instead of:
python setup.py build
and that solved it. You could probably add these to your PATH as an alternative.
Also, for anyone googling this in the future, you may have to modify the link.txt in Build/src/CMakeFiles/gpuarray.dir to:
1) omit -arch=i386
2) add -F/Library/Frameworks
after running make in the Build/ directory it has you create.
I think you forgot to run
make
make install
after cmake.
I installed it by following commands:
mkdir build && cd build
cmake ..
make && make install
cd .. && python setup.py install

Cmake is not able to find Python-libraries

Getting this error:
sudo: unable to resolve host coderw#ll
-- Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108
(message):
Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:315
(_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindPythonInterp.cmake:139
(FIND_PACKAGE_HANDLE_STANDARD_ARGS)
Code/cmake/Modules/FindNumPy.cmake:10 (find_package)
CMakeLists.txt:114 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/coderwall/Desktop/rdkit/build/CMakeFiles/CMakeOutput.log".
See also "/home/coderwall/Desktop/rdkit/build/CMakeFiles/CMakeError.log".
I have already installed:
sudo apt-get install python-dev
Environment variable are already set as follow:
PYTHON_INCLUDE_DIRS=/usr/include/python2.7
PYTHON_LIBRARIES=/usr/lib/python2.7/config/libpython2.7.so
Location of python.h : /usr/lib/include/python2.7/python.h
Location of python libs: /usr/lib/python2.7/
How to solve this?
You can fix the errors by appending to the cmake command the -DPYTHON_LIBRARY and -DPYTHON_INCLUDE_DIR flags filled with the respective folders.
Thus, the trick is to fill those parameters with the returned information from the python interpreter, which is the most reliable. This may work independently of your python location/version (also for Anaconda users):
$ cmake .. \
-DPYTHON_INCLUDE_DIR=$(python -c "import sysconfig; print(sysconfig.get_path('include'))") \
-DPYTHON_LIBRARY=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
If the version of python that you want to link against cmake is Python3.X and the default python symlink points to Python2.X, python3 -c ... can be used instead of python -c ....
In case that the error persists, you may need to update the cmake to a higher version as stated by #pdpcosta and repeat the process again.
For me this is helpful:
# if using python2
apt-get install python-dev
# if using python3
apt-get install python3-dev
I hit the same issue,and discovered the error message gives misleading variable names. Try setting the following (singular instead of plural):
PYTHON_INCLUDE_DIR=/usr/include/python2.7
PYTHON_LIBRARY=/usr/lib/python2.7/config/libpython2.7.so
The (plural) variables you see error messages about are values that the PythonLibs sets up when it is initialised correctly.
Even after adding -DPYTHON_INCLUDE_DIR and -DPYTHON_LIBRARY as suggested above, I was still facing the error Could NOT find PythonInterp. What solved it was adding -DPYTHON_EXECUTABLE:FILEPATH= to cmake as suggested in https://github.com/pybind/pybind11/issues/99#issuecomment-182071479:
cmake .. \
-DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") \
-DPYTHON_EXECUTABLE:FILEPATH=`which python`
I was facing this problem while trying to compile OpenCV 3 on a Xubuntu 14.04 Thrusty Tahr system.
With all the dev packages of Python installed, the configuration process was always returning the message:
Could NOT found PythonInterp: /usr/bin/python2.7 (found suitable version "2.7.6", minimum required is "2.7")
Could NOT find PythonLibs (missing: PYTHON_INCLUDE_DIRS) (found suitable exact version "2.7.6")
Found PythonInterp: /usr/bin/python3.4 (found suitable version "3.4", minimum required is "3.4")
Could NOT find PythonLibs (missing: PYTHON_LIBRARIES) (Required is exact version "3.4.0")
The CMake version available on Thrusty Tahr repositories is 2.8.
Some posts inspired me to upgrade CMake.
I've added a PPA CMake repository which installs CMake version 3.2.
After the upgrade everything ran smoothly and the compilation was successful.
Some last version of Ubuntu installs Python 3.4 by default and the CMake version from Ubuntu (2.8) only searches up to Python 3.3.
Try to add set(Python_ADDITIONAL_VERSIONS 3.4) before the find_package statement.
Remember to clean CMakeCache.txt too.
This problem can also happen in Windows. Cmake looks into the registry and sometimes python values are not set. For those with similar problem:
http://ericsilva.org/2012/10/11/restoring-your-python-registry-in-windows/
Just create a .reg file to set the necessary keys and edit accordingly to match your setup.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Python]
[HKEY_CURRENT_USER\Software\Python\Pythoncore]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6\InstallPath]
#="C:\\python26"
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6\PythonPath]
#="C:\\python26;C:\\python26\\Lib\\;C:\\python26\\DLLs\\"
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.7]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.7\InstallPath]
#="C:\\python27"
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.7\PythonPath]
#="C:\\python27;C:\\python27\\Lib\\;C:\\python27\\DLLs\\"
Note that if you are using cMake version 3.12 or later, variable PythonInterp and PythonLibs has been changed into Python.
So we use:
find_package(Python ${PY_VERSION} REQUIRED)
instead of:
find_package(PythonInterp ${PY_VERSION} REQUIRED)
find_package(PythonLibs ${PY_VERSION} REQUIRED)
see https://cmake.org/cmake/help/v3.12/module/FindPython.html for details.
I had upgraded to python3.8 on my system and had an incomplete install. Managed to fix it by installing the rest of the 3.8 packages:
sudo apt-get install python3.8 python3.8-dev python3.8-distutils python3.8-venv
Paste this into your CMakeLists.txt:
# find python
execute_process(COMMAND python-config --prefix OUTPUT_VARIABLE PYTHON_SEARCH_PATH)
string(REGEX REPLACE "\n$" "" PYTHON_SEARCH_PATH "${PYTHON_SEARCH_PATH}")
file(GLOB_RECURSE PYTHON_DY_LIBS ${PYTHON_SEARCH_PATH}/lib/libpython*.dylib ${PYTHON_SEARCH_PATH}/lib/libpython*.so)
if (PYTHON_DY_LIBS)
list(GET PYTHON_DY_LIBS 0 PYTHON_LIBRARY)
message("-- Find shared libpython: ${PYTHON_LIBRARY}")
else()
message(WARNING "Cannot find shared libpython, try find_package")
endif()
find_package(PythonInterp)
find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT)
In case that might help, I found a workaround for a similar problem, looking at the cmake doc :
https://cmake.org/cmake/help/v3.0/module/FindPythonLibs.html
You must set two env vars for cmake to find coherent versions.
Unfortunately this is not a generic solution...
cmake -DPYTHON_LIBRARY=${HOME}/.pyenv/versions/3.8.0/lib/libpython3.8.a -DPYTHON_INCLUDE_DIR=${HOME}/.pyenv/versions/3.8.0/include/python3.8/ cern_root/
In Python 3.2 and onward distutils.sysconfig is deprecated in favor of sysconfig.
To get all the variable names in data structure and inspect the situation we can use get_paths function
import sysconfig
sysconfig.get_paths()
which will return us a dict with all the relevant variable names as keys, and corresponding paths as values.
When we know the key we can get the value dynamically,
>>> sysconfig.get_path("include")
'C:\\Program Files\\Python310\\Include'
However, the most convenient feature of sysutils for this situation is that it can list all the variables at once from the command-prompt by invoking python -m sysconfig:
$ python -m sysconfig
Platform: "macosx-10.4-i386"
Python version: "3.2"
Current installation scheme: "posix_prefix"
Paths:
data = "/usr/local"
include = "/Users/tarek/Dev/svn.python.org/py3k/Include"
platinclude = "."
platlib = "/usr/local/lib/python3.2/site-packages"
platstdlib = "/usr/local/lib/python3.2"
purelib = "/usr/local/lib/python3.2/site-packages"
scripts = "/usr/local/bin"
stdlib = "/usr/local/lib/python3.2"
Variables:
AC_APPLE_UNIVERSAL_BUILD = "0"
AIX_GENUINE_CPLUSPLUS = "0"
AR = "ar"
ARFLAGS = "rc"
...
Maybe below command line works for you if all of above methods didn't work.
sudo apt-get install cython cython3
On Ubuntu 20 at least, since Python 2.7 is deprecated, you can:
sudo apt install python2.7-dev
And then PYTHON_INCLUDE_DIR can be set to /usr/include/python2.7

Installing rpy2 without admin privileges

I am having trouble installing the Python package rpy2. I have already compiled R as a shared library, but I do not have admin priviledges so I am trying to install rpy2 with:
pip install -user rpy2
However, I am getting the following error:
./rpy/rinterface/_rinterface.c:86:31: fatal error:
readline/readline.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
I have downloaded readline to:
/some/path/readline-6.2/
where I can see readline.h (I have also compiled readline just in case)
My question:
How can I make rpy2 (or pip) aware of this location with readline.h to avoid the header compilation error?
You'll need to actually install readline, not just download it, and then point rpy2 to it with CFLAGS and LDFLAGS.
Try this approach. It's almost working for me - I have the same problem, except an additional wrinkle that rpy2 seems to be linking against the system R instead of my homedir install.
First, I downloaded readline to ~/src/readline-6.2, and installed it with ./configure --prefix=$HOME && make && make install. (You need to install it somewhere, not just download the source.)
Then I re-compiled R with
CPPFLAGS="-I/usr/local/include -I$HOME/include/" \
LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib -L$HOME/lib64 -L$HOME/lib" \
./configure --prefix=$HOME --enable-BLAS-shlib --enable-R-shlib
make
make install
R is definitely now using that readline:
$ ldd ~/lib64/R/lib/libR.so | grep readline
libreadline.so.6 => /home/dsutherl/lib/libreadline.so.6 (0x00007f8104207000)
The same for my in-home install of Python (3.2.3, since h5py doesn't work with 3.3 yet):
CFLAGS="-I/usr/local/include -I$HOME/include/" \
LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib -L$HOME/lib64 -L$HOME/lib" \
./configure --prefix=$HOME
make
make install
And again:
$ ldd ~/lib/python3.2/lib-dynload/readline.cpython-32m.so | grep readline
libreadline.so.6 => /home/dsutherl/lib/libreadline.so.6 (0x00007fbfff5c2000)
Then I downloaded the rpy2 source and built that:
CFLAGS="-I/usr/local/include -I$HOME/include/" \
LDFLAGS="-L/usr/local/lib64 -L/usr/local/lib -L$HOME/lib64 -L$HOME/lib" \
python3 setup.py build --r-home $HOME/lib64/R install
This seemed successful, and ldding the .sos in site-packages/rpy2 links to the right libreadline...but to the system R, instead of mine, despite the explicit --r-home.
more simple :
yum install readline-devel.x86_64
run for me on centos 7
for debian/ubuntu
apt-get install libreadline-dev
Sometime in linux is needed an sudo apt-get upgrade, to get the news libraries, may work
This is another option, but too you need root privilegies ...
sudo apt-get install libreadline-dev

Categories

Resources