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
Related
I updated my system (Ubuntu 18.04) from Python 3.6 to Python 3.8, and reset the defaults so that python3 now points to Python 3.8 (and not 3.6). However, since then, the terminal has refused to open using Ctrl + Alt + T, and other obvious methods such as clicking on the icon itself.
When I run gnome-terminal - I get the following:
usernew#HP:/usr/lib/python3/dist-packages/gi$ gnome-terminal
Traceback (most recent call last):
File "/usr/bin/gnome-terminal", line 9, in <module>
from gi.repository import GLib, Gio
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
from . import _gi
ImportError: cannot import name '_gi' from partially initialized module 'gi' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gi/__init__.py)
I don't know what this means but I guess it definitely points to the fact that something went wrong during the update. I understand that there are other existing threads on similar issues, but most of them were about updating from Python2 to Python3, so I'm not sure if they're relevant.
Could someone help, please?
Important Update:
So, after reading this answer - I changed the gnome-terminal script's first line to #!/usr/bin/python3.6 instead of #!/usr/bin/python3.8 - and that solves the problem.
Also, when I type python3 in the terminal, I'm greeted with Python 3.8.2, as desired.
The question remains - Why did this work?
What was the actual problem? An explanation would help, so I really know what I'm doing.
Thanks!
You shouldn't change the symlink /usr/bin/python3 since a bunch of Ubuntu components depend on it, and Ubuntu-specific Python libraries like gi are built only for the Python build shipped with Ubuntu, which is version 3.6 on 18.04.
See Gnome terminal will not start on Ask Ubuntu (though note that it's about Ubuntu 16.04 which uses Python 3.5). So the best way to fix it is to revert the symlink:
sudo ln -sf python3.6 /usr/bin/python3
As for setting Python 3.8 as the default, you could put an alias in your bashrc:
alias python3=python3.8
But this will only affect the shell for your user. In scripts for example if you want to use Python 3.8 you'll have to write it, i.e. #!/usr/bin/env python3.8
I am trying to install and use PyGame. I am using Python 3.3.2 and Pygame "3.3 pygame-1.9.2a0" according to the installer. I downloaded it from https://bitbucket.org/pygame/pygame/downloads. I used an easy install, and after next-next type install, I opened the Python 3.3.2 Shell and typed "import pygame". I got this error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
ImportError: No module named 'pygame'
>>> import sys; print sys.path
SyntaxError: invalid syntax
I am also trying to install it with the PyCharm IDE, but I have NO clue how to do that either. The installer I'm using may be for 32 bit, which wouldn't be compatible with my 64 bit installation of Python, but I don't know how to tell and if so is there even a 64 bit version of PyGame for 64 bit? If anyone knows how to install PyGame for Python 3.3.2 please let me know. Thank you for your time.
If your python is a 64 bit version the binary install for the 32 bit will not work. However, there is a 64 bit version here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
If you're worried because they're unofficial don't. I have used many installations from that link for my 64 bit python and they're working great.
Currently, pygame is not available for 64 bit Python (or so it seems on Pygame Site).
The one you installed maybe 32 bit & thus causing the ImportError.
In Python 3.x, print is a function & hence the SyntaxError.
Pycharm for Python 3.x is available Pycharm Download
I would recommend using Python 3.x (32 bit) because most of the libraries seem to be compatible with it & also, 64 bit version doesn't provide much performance benefit as such.
I personally use PyScripter IDE
This maybe very handy at times - Very useful precompiled binaries for several libraries
From pygame website:
windows 64bit users note: use the 32bit python with this 32bit pygame.
So either donwload a 32bit python, then install with the 32bit pygame installer, or download the unofficial 64bit pygame build at here.
Ever time I use PyCharm, I go to File > Settings > Project: (project name) > Interpreter > Plus Icon > (search pygame and click install package) This is because I think that you are using a pycharm venv and I think that that isolates outer packages so I do it this way
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
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.
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