I previously installed Python in /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6. then after the Lion update I installed it again in /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6. But when I install any Python package using MacPorts, the installation fails with the following message:
CPATH='/opt/local/include' MACOSX_DEPLOYMENT_TARGET='10.7' LIBRARY_PATH='/opt/local/lib' F90FLAGS='-m64' CC_PRINT_OPTIONS_FILE='/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_mercurial/mercurial/work/.CC_PRINT_OPTIONS' LDFLAGS='-arch x86_64' FCFLAGS='-m64' OBJCFLAGS='-arch x86_64' FFLAGS='-m64' CC_PRINT_OPTIONS='YES'
:debug:build Assembled command: 'cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_mercurial/mercurial/work/mercurial-1.9" && /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 setup.py --no-user-cfg build'
:debug:build Executing command line: cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_mercurial/mercurial/work/mercurial-1.9" && /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 setup.py --no-user-cfg build
:info:build sh: /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6: No such file or directory
:info:build shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_mercurial/mercurial/work/mercurial-1.9" && /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6 setup.py --no-user-cfg build " returned error 127
:error:build Target org.macports.build returned: shell command failed (see log for details)
:debug:build Backtrace: shell command failed (see log for details)
while executing
"command_exec build"
(procedure "portbuild::build_main" line 8)
invoked from within
"$procedure $targetname"
:info:build Warning: the following items did not execute (for mercurial): org.macports.activate org.macports.build org.macports.destroot org.macports.install
:notice:build Log for mercurial is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_devel_mercurial/mercurial/main.log
This happened while installing mercurial. I tried setting the default Python as the active one, but it was no use.
How can I make MacPorts use the version of Python I want? I should able to tell it this is the version and place which needs to be used.
What do you mean by you installed Python 2.6 again in /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6? That's the location of the Apple-supplied Python 2.6 in Lion. There are also Apple-suppled Python 2.7 and 2.5 versions in that framework. Do not modify or delete anything in /System/Library! The MacPorts version is installed as before in /opt/local/.
Since upgrading to Lion, have you:
downloaded the Xcode 4.1 installer from the Mac App store and then run the installer for it (found in /Applications)?
Have you updated your MacPorts ports setup to the latest updates to support Lion?
$ sudo port selfupdate
$ sudo port -u upgrade outdated
Are you using the MacPorts mercurial port?
$ sudo port install mercurial
Have you modified your PATH to include /opt/local/bin or are you using the absolute path to the Macports Python: /opt/local/bin/python2.6
I find it best to work with virtualenv when programming python - then there's no mystery about which dependency is where, and installing packages is a breeze with pip or easy_install. If you google it, you can see a bunch of useful blog posts on how to set it up and use it effectively.
Related
I am trying to install a python project on a server where I don't have root access. I've managed to install virtualenv and pip locally, but the pip install is now failing when trying to install uwsgi (specifically trying to build wheel) with several error: Python.h: No such file or directory errors.
From what I've gathered I need to install python-dev, but as I don't have sudo access I've had to download and extract the python-dev package.
Where I'm stuck now is how to link python-dev to the python I've installed in my virtualenv.
Server details:
$ uname -a
4.9.0-12-amd64 #1 SMP Debian 4.9.210-1 (2020-01-20) x86_64 GNU/Linux
$ python --version
Python 3.5.3
First, could you ask your admin for help?
OK, let's summarize: python.h: No such file or directory looks like the C compiler could not find the necessary header files. Those files are contained in the python-dev package, but you are not permitted to install it. You have downloaded the package and extracted its files somewhere.
Now you should set the xx_PATH environment variables that gcc uses to find additional library and header files locations, see the docs and the example here for details and try the installation again.
Anyway this fixes only the first compilation error.
I have been able to successfully install cx_Oracle for use with Python 3.4 on my Windows 8 laptop, and I am now trying to get the same setup (cx_Oracle with Python 3.4) onto a Linux machine. When running the setup.py file from cx_Oracle-5.1.3.tar.gz, I end up with this error:
sudo python3 setup.py install
Traceback (most recent call last):
File "setup.py", line 135, in <module>
raise DistutilsSetupError("cannot locate an Oracle software " \
distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation
Following some other answers I looked at (easy_install cx_Oracle (python package) on Windows, https://gist.github.com/jarshwah/3863378) I have installed these 3 instant client rpms:
rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.i386.rpm
And then I set ORACLE_HOME to the folder that they were installed to, which is supposed to help python identify the location of the oracle files so it can do the installation properly.
I still get the same "cannot locate an Oracle software installation" error each time I try to run the setup.py file.
Any idea what I need to do to be able to successfully install cx_oracle?
Update for more info:
echo $ORACLE_HOME returns /instantclient_12_1, which is where the rpm files installed to.
This is the contents of my /instantclient_12_1 directory:
adrci libnnz12.so libsqlplusic.so tnsnames.ora
BASIC_README libocci.so libsqlplus.so tnsnames.ora_andy
genezi libocci.so.12.1 ojdbc6.jar uidrvci
glogin.sql libociei.so ojdbc7.jar xstreams.jar
libclntshcore.so.12.1 libocijdbc12.so sdk
libclntsh.so libons.so sqlplus
libclntsh.so.12.1 liboramysql12.so SQLPLUS_README
This is a bit different from the directory I have for my Windows 8 install - that one has .dll and .sym files, like orasql12.dll. Should the Linux version of the instant client install have different files?
Update with partial solution:
I found a solution that installed cx_Oracle properly, but only during that shell instance:
I set these two environment variables:
export ORACLE_HOME=/instantclient_12_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
And then I created a Symbolic link:
ln -s libclntsh.so.12.1 libclntsh.so
After that, going to the cx_oracle folder and doing this worked:
python3 setup.py build
python3 setup.py install
For some reason, sudo python3 setup.py install did not work for this.
Update with link to related question:
My next problem is getting the environment variables to persist outside of the shell instance so I don't have to define the environment variables each time. The environment variables I put in profile.d show up when I echo them, but python fails to import cx_oracle properly, and I have to export the environment variables again for some reason. I don't know the proper procedure for posting a different question related to one, so I opened a new question here:
Linux profile.d environment variables don't work with cx_oracle in Python
Please help me out with this, I feel completely stuck on what to try to make it work. The environment variables show up when I echo them, but they only seem to be functional if I export them again before running the python code.
Updated
As Petriborg suggested, setting LD_RUN_PATH at build time will include the path to the Oracle shared library files in the cx_Oracle shared library that is built during installation. This obviates the need for LD_LIBRARY_PATH as I suggested in my first answer.
For the RPMs that you are using, ORACLE_HOME should be set to /usr/lib/oracle/12.1/client. If you are using pip:
$ export ORACLE_HOME=/usr/lib/oracle/12.1/client
$ export LD_RUN_PATH=/usr/lib/oracle/12.1/client/lib:$LD_RUN_PATH
$ pip install cx_Oracle
$ python -c 'import cx_Oracle; print(cx_Oracle.version)'
5.1.3
Read this documentation for some info on installing and executing applications that use the client libraries.
When I tried installing cx_Oracle with LD_LIBRARY_PATH variable alone in Ubuntu 16.04 with python 2.7.12 and Oracle client 12.1.0.2 pip install fails and is looking for header files which are no more available with Oracle 12.1.0.2 client. It works fine with LD_RUN_PATH
I am running RHEL5 , and i have python 2.4 installed on it.Please dont ask why the native version?
My question is that in my home directory i want to install python2.6 with selected packages only and also most importantly i dont want any of the library os or any other which deals with system calls or mail box preferences(sending mail to be prohibited).Is it possible to install a python version with selected libraries only.
So now on the system python 2.4 and selected libraries of 2.6 exists
This may not be quite what you're looking for... but the following steps will accomplish something similar to this (if you have root access). The below steps assume you are on i386 architecture.
1) Install Python 2.6 in parallel on your system (requires root). It is available at the EPEL repository:
$ rpm -i http://download.fedora.redhat.com/pub/epel/5/i386/python26-2.6.5-6.el5.i386.rpm
2) Install setuptools by running (again as root):
$ curl http://peak.telecommunity.com/dist/ez_setup.py | python26
3) Install virtualenv (http://pypi.python.org/pypi/virtualenv):
$ easy_install-2.6 virtualenv
4) From your home directory, create a new python environment:
$ cd ~
$ virtualenv --no-site-packages my-env
5) Activate the environment:
$ source my-env/bin/activate
You can now use easy_install to install whatever packages you want, remove anything you don't want from ~/my-env/lib/python26/site-packages, etc.
To let you know you are working in the virtual environment, your prompt will look like this:
[(my-env)you#host ~]$
One thing you have to be careful about is python scripts that start with #!/usr/bin/python, as they will not use the environment version. To ensure that the environment version is used, execute your script like this:
$ python your-script.py
Or you can specifically specify your environment version in your scripts:
#!/home/your-name/my-env/bin/python
Try ActivePython - it installs to an isolated directory (eg: /opt/ActivePython-2.6), and you can use PyPM to install third-party packages.
I am trying to get started on working with Python on Django I am by profession a PHP developer and have been told to set up django and python on my current apache and mysql setup however I am having trouble getting the Mysqldb module for python to work, I must of followed about 6 different set of instructions, I am running snow leopard and have mysql installed natively it is not part of MAMP or similar. Please can some tell me where I need to start and what steps I need to follew I would be most grateful.
Thanks
On MAC OS X 10.6, Install the package as usual. The dynamic import error occurs because of wrong DYLD path. Export the path and open up a python terminal.
$ sudo python setup.py clean
$ sudo python setup.py build
$ sudo python setup.py install
$ export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
$python
import MySQLdb
Now import MySQLdb should work fine.
You may also want to manually remove the build folder, before build and install. The clean command does not do a proper task of cleaning up the build files.
I'd recomend installing macports (latest svn trunk) and installing mysql from there.
sudo port install mysql5-server
Download the MySQL-python-1.2.2 source
make sure /opt/local/lib/mysql5/bin is in your path or edit site.cfg to include:
mysql_config = /opt/local/lib/mysql5/bin/mysql_config
Comment out line 38 of _mysql.c
// #define uint unsigned int
Then run:
sudo python setup.py install
should be all good.
[Partial Answer]
You'll have more fun pulling out your teeth. MySQL/Django/Mac is a disaster. This is the farthest I've gotten:
Get MySQLDB 1.2.3
Go into that and modify setup_posix.py:
Change:
mysql_config.path = "mysql_config"
To (depending on the version number of your MySQL):
mysql_config.path = "/usr/local/mysql-5.1.34-osx10.5-x86_64/bin/mysql_config"
python setup.py build
python setup.py install
Here's a good article
First and foremost, make sure that XCode is installed. Without XCode, many pieces of the built-in Apache2 server important to developers are missing; most notably, the GNU Compiler Collection, which I would think to be requisite for MySQL bindings.
One of the key things here is to make sure you're running both MySQL and the Python adaptor in 64 bit. The default Python 2.6.1 install on Snow Leopard is 64 bit so you must install MySQL in 64 bit and build the MySQLdb adapter in 64 bit.
Make sure you have the latest Xcode installed
Install 64-bit MySQL from DMG - http://dev.mysql.com/downloads/mirror.php?id=401941#mirrors
Download MySQL-python-1.2.3 from http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
Extract and make the following edit to site.cfg:
mysql_config = /usr/local/mysql/bin/mysql_config
Then from your terminal run
ARCHFLAGS="-arch x86_64" python setup.py build
sudo python setup.py install
You should then open a Python shell and type:
import MySQLdb
If you don't get any errors you're golden.
Xcode was installed.
Follow these instructions for setting up apache/php/mysql:
http://maestric.com/doc/mac/apache_php_mysql_snow_leopard
I installed the free 32-bit version of EPD (this is optional but I wanted numpy/scipy).
Make sure you have these lines in your ~/.profile (the second line is only if you installed EPD):
export PATH=/usr/local/mysql/bin/:/usr/local/bin:/usr/local/sbin:$PATH
export PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
Downloaded mysqldb and run:
python setup.py build
sudo python setup.py install
Install the official release of Django or web2py. Everything worked after that. You can try the "Writing Your First Django App, Part 1" to test it out where in settings.py use:
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = 'Django Polls'
DATABASE_USER = '*****'
DATABASE_PASSWORD = '*****'
DATABASE_HOST = '127.0.0.1'
DATABASE_PORT = '3306'
I also use Navicat Lite and Sequel Pro for working with MySQL.
Pydev is a nice IDE to use with Django.
Install the newest 64bit DMG version of MySQL. Remember to backup your databases if you already have MySQL installed.
enter this line in terminal:
sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
Edit the file setup_posix in the mysql-python installation directory.
Change the line
mysql_config.path = "mysql_config"
to
mysql_config.path = "/usr/local/mysql/bin/mysql_config"
Myslq-Python needs a 64bit Version of Python. The new Python 2.7 64bit version creates an alias in /usr/local/bin/python.
Enter the following lines in the mysql-python folder
sudo /usr/local/bin/python setup.py clean
sudo ARCHFLAGS="-arch x86_64"
sudo /usr/local/bin/python setup.py build
sudo /usr/local/bin/python setup.py install
And finally try it out:
python
import MySQLdb
You could make your life a lot easier (especially on Lion) by just installing Mariadb instead:
http://mariadb.org/
It's a drop-in replacement for MySQL and is plug&play on OSX. The only thing you don't get is the MySQL system setting.
I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:
error: command 'gcc' failed with exit status 1
As far as I understood the problems appears because version of my Python is 2.4.3 and SQLite is integrated in Python since 2.5. However, I also found out that it IS possible to build sqlite for Python 2.4 (using some tricks, probably).
Does anybody know how to build sqlite for Python 2.4?
As another option I could try to install higher version of Python. However I do not have root privileges. Does anybody know what will be the easiest way to solve the problem (build SQLite fro Python 2.4, or install newer version of Python)? I have to mention that I would not like to overwrite the old version version of Python.
Thank you in advance.
You can download and install Python to your home directory.
$ cd
$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz
$ tar xvzf Python-2.6.2.tgz
$ cd Python-2.6.2
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install
Then, (if you are using bash) in your .bash_profile do
export PATH=$HOME/opt/bin/:$PATH
export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH
Then, source the file to make it available
$ cd
$ source .bash_profile
$ python -V
where python -V will return the python version. If the correct version appears, any packages that you run with Python's setup.py util (assuming the developer followed the correct conventions) will install in ~/opt/lib/python2.x/site-packages directory.
Download pysqlite here, cd into the directory you downloaded to, unpack the tarball:
$ tar xzf pysqlite-2.5.5.tar.gz
then just do (if your permissions are set right for this; may need sudo otherwise):
$ cd pysqlite-2.5.5
$ python2.4 setup.py install
one error does appear in the copious output:
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/pysqlite2/test/py25tests.py", line 48
with self.con:
^
SyntaxError: invalid syntax
since as clearly shown that file is for py 2.5 tests only (with statement not present in 2.4!-). Nevertheless the install is successful:
$ python2.4 -c'import pysqlite2'
$
All this is on Mac OS X 10.5 but using python2.4 separately installed from the system-supplied Python 2.5.
The error you report doesn't tell us much -- maybe you're missing the headers or libraries for sqlite itself? Can you show us other output lines around that single error msg...?
If you don't have root privileges, I would recommend installing a more recent version of Python in your home directory and then adding your local version to your PATH. It seems easier to go that direction than to try to make sqlite work with an old version of Python.
You will also be doing yourself a favor by using a recent version of Python, because you'll have access to the numerous recent improvements in the language.
I had the same trouble with gcc failing with Ubuntu Karmic. I fixed this by installing the python-dev package. In my case, I'm working with python2.4, so I installed the python2.4-dev package. The python-dev package should work for python2.6.