I recently installed python 3.3.2
Im trying to install NumPy, when I call import NumPy from the command line I get the following error:
import numpy
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named 'numpy'
From what I've read it may have to do with having multiple version of Python installed.
The only problem is when I try run the Which Python command I get another error?
which python
File "<console>", line 1
which python
^
SyntaxError: invalid syntax
Any Ideas?
Thanks
What you have to do depends on the operating system you are using. I'me assuming you are using Linux. If you are using Linux with some kind of package manager, you should use a numpy package that is expressly for the python version you want to us it with. The same goes if you are using windows.
Note that you can have different versions of python installed, but in general only one is symlinked to python. Running ls -l /usr/local/bin/python should tell you what is the default version on your machine. If you have multiple versions, there should also be programs named python2 and python3. Using ls -l /usr/local/bin/python2 and ls -l /usr/local/bin/python3 will show you the which versions you really have.
On linux and other UNIX-like systems, you can usually find Python's files in a subdirectory of /usr/local/lib. For python 2.7 this will be /usr/local/lib/python2.7, for 3.2 it will be /usr/local/lib/python3.3. These directories will have a subdirectory site-packages. In those site-packages you should look for a subdirectory numpy. If you find /usr/local/lib/python2.7/site-packages/numpy but not /usr/local/lib/python3.3/site-packages/numpy, then numpy was not installed for 3.2.
Edit: In Windows, Python usually installs itself in the root of the C: drive, like C:\Python27 or C:\Python33. I don't have a windows machine handy, but there should be a site-packages subdirectory in both of them as well. Look for the numpy subdirectory in there.
For windows, you can find precompiled binaries for mumpy here. You just need to know is you have a 32 bit (win32) or 64 bit version (amd64) of windows. E.g. for python 3.3 and 2 32-bit windows I would suggest numpy-MKL-1.7.1.win32-py3.3.exe.
Type open a command prompt and type python It will then tell you what version you are running as it opens the interactive python editor.
Otherwise get your numpy from here These are compiled binaries and should be the most straightforward to install for a windows user
Related
I'm trying to run git-cola from Red Hat Enterprise Linux Server release 6.5 and receive:
Traceback (most recent call last):
File "....../bin/git-cola", line 24, in <module>
from argparse import ArgumentParser
ImportError: No module named argparse
I think I have all of the required packages installed:
* git-1.7.1-3.el6_4.1.x86_64
* python-2.6.6-51.el6.x86_64
* PyQt4.x86_64 0:4.6.2-9.el6
* /usr/lib/python2.6/site-packages/argparse-1.2.1-py2.6.egg
I read in other blogs that there may be a problem with Python 2.6 and may need to move to 2.7.
Additional information - #iljau noticed that argparse is in a 32 bit lib, while the rest of python is in 64 bits. I would have expected that:
easy_install argparse
would have sorted this out and installed the 64 bit version.
Additional question: Does anyone know how to install the 64 bit version of argparse. It is not apparent to me from searching the internet. I will continue looking.
I installed argparse by downloading the tar file and
python setup.py install
However, it still installed it in the lib rather than lib64 path - and it looks like a 64 bit install. So something else must be the problem in referencing argparse properly. I don't know Python enough to debug it, but I suspect that git-cola needs some work for Python 2.6.
As a simple solution copy argparse.py from https://code.google.com/p/argparse/source/browse/argparse.py to your project folder.
And indeed, for Python 2.6 argparse needs to be installed separately.
From: https://pypi.python.org/pypi/argparse
As of Python >= 2.7 .. the argparse module is maintained within the Python standard library. For users who still need to support Python < 2.7 .. it is also provided as a separate package, which .. also supports older Python versions.
But even after you install argparse, it may refuse to work for some mysterious reasons.
Additional debugging tips may be found in answers and comments to question "ImportError: No module named argparse".
I had the same problem on RHEL6 and the solution was installing the package python-argparse.noarch:
yum install python-argparse.noarch
then everything was fine.
The new packages were installed in the path:
/usr/lib/python2.6/site-packages
Installing them with sudo left the newly installed directories and files unreadable by all. A recursive chmod to open all the installed paths as readable to all solved the problem:
chmod -R u+rwX,go+rX,go-w <new directories and files>
Looks like argparse is missing.
yum install python-argparse
I currently have Python2.7, and Python3.3 installed on a Mac. I am trying to install matplotlib so that I can create candlestick, and line graphs. I have tried multiple methods of installing matplotlib, but they are all failing. For example:
port install py27-matplotlib
No broken files found.
MacBook$ python2.7
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
attempts at source builds off matplotlib-1.1.1 lead to C header errors.
The parent problem that I am trying to solve is to create candlestick, and line plots. Is there another library better suited to this maybe?
seems like you have a python's path issue and maybe this post will be helpful.
update: i reemphasized my hint at the path issue because of a comment...
You need to use the MacPorts-supplied Python 2.7, not the Apple-supplied system Python 2.7. Try:
/opt/local/bin/python2.7
To avoid having to use absolute paths, make sure that the recommended MacPorts bin directories are on your shell PATH and run sudo port select python python27 to select the MacPorts Python 2.7 as the default for /opt/local/bin/python.
Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion)
One other thing: I have installed oracle 32 bit, not sure if that was correct.
Traceback (most recent call last):
File "reader.py", line 9, in <module>
import cx_Oracle
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 7, in <module>
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
Referenced from: /Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so
Expected in: flat namespace
in /Users/me/.python-eggs/cx_Oracle-5.1.1-py2.7-macosx-10.7-intel.egg-tmp/cx_Oracle.so
They key problem seems to be not being able to locate _OCIAttGet, and I think this means that it cant find a lib file or something.
Found on the web, someone talking about DYLD_LIBRARY_PATH, but mine is set, however he mentioned it in cxoracle.cfg file, that I can not locate, is this my problem?
EDIT
After trying to run it with 32 bit mode python, I see a different error.
Traceback (most recent call last):
File "reader.py", line 9, in <module>
import cx_Oracle
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 7, in <module>
File "build/bdist.macosx-10.7-intel/egg/cx_Oracle.py", line 3, in __bootstrap__
ImportError: No module named pkg_resources
I could not get the oracle 64 bit versions to run on my computer, kept getting segmentation faults when i ran sqlplus, so thats why I am using the 32.
SECOND EDIT
Actually no matter what i install, it is not the right version.. 32 bit version
ld: warning: ignoring file /opt/oracle/instantclient10_2/libclntsh.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
64 bit version:
ld: warning: ignoring file /opt/oracle/instantclient10_2/libclntsh.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64)
I am going to try 11g, but that only has a 64 bit version.
To compile cx_Oracle so it'll work on OS X needs a couple of things configured. The important bits are:
Create a virtualenv with a python interpreter stripped to 32-bit only. In the virtualenv bin directory ($WORKON_HOME/*name_of_virtualenv*/bin):
% mv python python.fat
% lipo python.fat -remove x86_64 -output python
Even though Python is now thin its configuration is not so we need to force things using an obscure environment variable that distutils will pick up:
ARCHFLAGS="-arch i386" pip install cx_Oracle
If you are using the Apple-supplied Python 2.7, it will prefer to run in 64-bit mode and that will be a problem if you did install 32-bit-only Oracle libraries. You can try forcing that Python to run in 32-bit mode by starting it this way:
arch -i386 python2.7
If you are careful to always launch python via /usr/bin/python, you could also use either of the methods described in Apple's man page for Python, i.e. setting a VERSIONER_PYTHON_PREFER_32_BIT environment variable or setting a permanent default via defaults.
Steps to install to oracle client on mac ox 10.8.5 for connecting oracle from python. (There is bug due to it 64 bit doesn't work for mac ox 10.8.5 )
Go to http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
Download instantclient-basic-macos.x32-11.2.0.3.0.zip
Download instantclient-sdk-macos.x32-11.2.0.3.0.zip
Create new folder under /Users/< your username>/ora_32(you can name what you want )
Move the zip files instantclient-sdk-macos.x32-11.2.0.3.0.zip and
instantclient-basic-macos.x32-11.2.0.3.0.zip to
/Users/< your username>/ora_32 Command below
mv insta*32* /Users/< your username>/ora_32/
Unzip instantclient-basic-macos.x32-11.2.0.3.0.zip and
instantclient-sdk-macos.x32-11.2.0.3.0.zip
Command below
cd /Users/< your username>/ora_32/
unzip instantclient-basic-macos.x32-11.2.0.3.0.zip
unzip instantclient-sdk-macos.x32-11.2.0.3.0.zip
it will create a folder instantclient_11_2 under
/Users//ora_32/
cd to /Users/< your username>/ora_32/instantclient_11_2
and Create the below symbolic link which
will be used in the installation of cx_Oracle.( Mentioned below )
ln -s libclntsh.dylib.11.1 libclntsh.dylib
ln -s libocci.dylib.11.1 libocci.dylib
Export the environment variables for the current session
or you can add them in bash profile to invoke every time you open
a new terminal.
export ORACLE_HOME=/Users/<your username>/ora_32/instantclient_11_2
export LD_LIBRARY_PATH=$ORACLE_HOME
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export VERSIONER_PYTHON_PREFER_32_BIT=yes
export PATH=$PATH:/Users/<your username>/ora_32/instantclient_11_2
Download cx_Oracle (option source code only)
at the link http://cx-oracle.sourceforge.net
Untar the cx_Oracle tar file and it will create a cx_Oracle-5.1.2 folder
cd to that folder cx_Oracle-5.1.2
Run the below command it will install cx_Oracle and then
sudo easy_install cx_Oracle
You can check by going to python prompt and typing import cx_Oracle
Not certain if you're still having problems with this, but here is how I got it to work.
I followed the instructions listed here (using the 32-bit downloads from Oracle):
http://www.xairon.net/2011/05/guide-installing-cx_oracle-on-mac-os-x/
I then had the same error you listed:
ImportError: dlopen(/Library/Python/2.7/site-packages/cx_Oracle.so, 2): Symbol not found: _OCIAttrGet
Referenced from: /Library/Python/2.7/site-packages/cx_Oracle.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/cx_Oracle.so
The problem was from Apple's Python distribution running in 64-bit mode by default.
Once I forced the Apple supplied Python to use 32-bit (from Ned's recommendation), it worked!
To do that:
$export VERSIONER_PYTHON_PREFER_32_BIT=Yes
To make it permanent:
$defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
I had this same problem. I'm using Mac OS X 10.8.3.
After 4 hours of trying various solutions, I finally realized that this was the result of having installed the 32-bit version of Oracle InstantClient, which conflicted with the 64-bit version of python.
To resolve: I uninstalled python (and some dependencies), then reinstalled the universal version. I followed the directions in this post to strip the x86_64 from the python binary in my virtualenv. This allowed the 32-bit Oracle InstantClient to work with the 32-bit python binary.
I am hesitant to use the 64-bit Oracle InstantClient, due to some other posts I saw while researching this issue.
I've just bought a new computer with Lion on it. I've downloaded and installed both Python 2.7 and wxPython 2.8 (for 2.7). I know Python comes with the system, but I rather go with the official one.
Anyway, upon typing "import wx" on the IDLE, I get the following message:
Traceback (most recent call last):
File "", line 1, in
import wx
File "/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/init.py", line 45, in
from wx._core import *
File "/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/_core.py", line 4, in
import core
ImportError: dlopen(/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/core.so, 2): no suitable image found. Did find:
/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.7/site-packages/wx-2.8-mac-unicode/wx/core.so: no matching architecture in universal wrapper
I believe it happens because wxPython only supports 32-bit, but I can't figure out how to force python to run on 32-bit.
Anyone could help?
Thank you in advance.
wxPython 2.9 supports 64-bit on Mac too (see the Development version section and look for the cocoa build: http://wxpython.org/download.php). This was also discussed on the mailing list, and multiple users confirmed that wx works on Lion: https://groups.google.com/forum/#!searchin/wxpython-users/lion/wxpython-users/LvjSVqqMMpQ/U0QJXEeBpLQJ
This may not work for python versions below 2.9. Running 'python' did not work for me...I am using 2.7 for compatibility. But figured out that 'python' may be an alias for a 64 bit mode and for some reason the arch command does not work.
So, here is what I have to use under Lion to get wx to work (this works for 2.6 or 2.7):
$ arch -i386 python2.7
Then when python loads:
import wx
works fine. You may have to call the specific python with the arch command, such as python2.7, or whatever version you are using.
This should start it up in 32-bit mode, I'm not sure if it will fix the wx problem
% arch -i386 python
You can force python to run in 32-bit mode by adding the following line to your shell profile
export VERSIONER_PYTHON_PREFER_32_BIT=yes
I am trying to follow the instructions for the accepted answer to "PyObjC development with Xcode 3.2". I will repost them here since I don't have enough rep to comment on the actual question:
Here's what I have done to get PyObjC working in Snow Leopard:
Using the Finder, I went to Go > Connect to Server... and connected to http://svn.red-bean.com/pyobjc/trunk/pyobjc/pyobjc-xcode/ as a guest.
I then made a folder called Xcode on my local system at ~Library/Application Support/Developer/Shared/Xcode/. (You may already have this folder, but I hadn't customized anything for myself yet).
I copied the File Templates folder from the red-bean server into my new Xcode folder.
Copied the Project Templates folder to some other place, for example, the Desktop.
Using the Terminal, navigated to the temporary Project Templates folder on my Desktop and ran this command to "build" the template.:
$ cd ~/Desktop/Project\ Templates/
$ ./project-tool.py -k -v --template ~/Desktop/Project\ Templates/Cocoa-Python\ Application/CocoaApp.xcodeproj/TemplateInfo.plist Cocoa-Python\ Application ~/Library/Application\ Support/Developer/Shared/Xcode/Project\ Templates/Cocoa-Python\ Application
When I try to run the line that starts with ./project-tool.py, I get the following error in Terminal:
Traceback (most recent call last):
File "./project-tool.py", line 22, in <module>
from Foundation import NSDictionary
ImportError: No module named Foundation
I am running Snow Leopard and have installed Xcode 3.2.1 and have read that this module should already be installed and working. I've read that you can test if the PyObjC modules are working by running >>> import objc in the Python command-line. When I run this, I get:
>>> import objc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named objc
Could anyone help me dispel this error? It seems like I should be able to do all of this automatically with my Snow Leopard installation, but I can't.
I had the same problem. Mine was caused I think by using homebrew to install my own Python to tinker with.
Because I was worried about mixing python versions, rather than creating the link as described above, I installed a new pyobjc using:
$ pip install pyobjc
For interest, from (http://pythonhosted.org/pyobjc/)
The PyObjC project aims to provide a bridge between the Python and Objective-C programming languages.
Okay, it turned out that, amending mjv's answer, I was able to get it working by typing
export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/PyObjC/"
before executing the ./project-tool.py line. I still find it ridiculous that I had to do this and if anyone can see why, I would be delighted to know.
Doing this also got the
>>> import objc
line working.
It's because PyObjC is there :
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC
Edit :
I found how to make "import objc" work, just :
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/"
It will add all the directories to the python path (sys.path)
for python 2.7
export PYTHONPATH="/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/"
One of two things:
Either the Fundation module doesn't exists
Or Python interpretor doesn't know when to find this file
Python looks for modules in the PythonPath
See this SO question for more details on how Python Path is created etc.
Run python -v to trace import statements, this work for interactive mode too.
I could access a Python installation with Foundation on my OSX by running /usr/bin/python file-to-run.py
remove your python or remove site-packages/Foundation | site-packages/foundation
pip3 install pyobjc
the name Foundation is in conflict with https://pypi.org/project/foundation/
I found the foundation folder in /usr/local/lib/python3.9/site-packages/ next to the AppKit folder. After renaming it to Foundation (with uppercase F), the import worked. The Filesystem is not case-sensitive but it seems some part of the import implementation is.
Saw it mentioned in another comment and I too ran into this problem due to installing Python via homebrew. My pyobjc installation wound up going to the Python homebrew installation, yet my pythonpath was linked to the Python that comes bundled with macOS, so there was this big disconnect and I had no luck getting pythonpath re-routed in .zshrc or .zprofile.
In the end, these steps resolved the issue:
brew uninstall python
pip3 install -U pyobjc