I've been using virtualenv + pip for python development. I'm not sure what happened, but suddenly whenever I try to run a command-line tool or import libraries, I get this error message:
Traceback (most recent call last):
File "/Users/kyle/.virtualenvs/fj/bin/pip", line 4, in <module>
import pkg_resources
File "/Users/kyle/.virtualenvs/fj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 698, in <module>
the platform/python version defined at initialization are added.
File "/Users/kyle/.virtualenvs/fj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 701, in Environment
search_path = sys.path
File "/Users/kyle/.virtualenvs/fj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 96, in get_supported_platform
'Environment', 'WorkingSet', 'ResourceManager',
File "/Users/kyle/.virtualenvs/fj/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 221, in get_build_platform
if provDarwin:
File "/Users/kyle/.virtualenvs/fj/lib/python2.6/distutils/__init__.py", line 14, in <module>
exec open(os.path.join(distutils_path, '__init__.py')).read()
IOError: [Errno 2] No such file or directory: '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/__init__.py'
From what I can decipher, Python is trying to find distutils_path in the Mac OSX system version Python, not my virtualenv version like it should be.
Not sure why this suddenly started happening. Maybe a recent OSX update? Another possibility is that my hard drive was about to die, so Apple gave me a new one and ran Migration Assistant. Maybe something didn't transferred across correctly?
I encountered this distutils/__init__.py problem when transitioning to OS X 10.7 Lion (from OS X 10.5 Leopard) and using Migration Assistant. I've already installed Xcode 3.2.6 -- thus resolving the missing install_name_tool problem.
Migration Assistant brought over my previous virtualenvs, but since they were based on Leopard's Python 2.5, I figure I need to recreate each of them with the current system Python 2.7.
easy_install was already in the PATH -- probably because it was bundled with Lion's Python 2.7; it seems unlikely to be the result of Migration Assistant. I used easy_install to install virtualenv.
This problem, it seems to me, doesn't have anything to do with Xcode or lack thereof. It's a peculiar line in a file placed in the new virtual env by the virtualenv command:
File "/path/to/my/virtualenv/lib/python2.7/distutils/__init__.py", line 16, in
exec(open(os.path.join(distutils_path, '__init__.py')).read())
IOError: [Errno 2] No such file or directory: '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/__init__.py'
The issue is that, in the Python 2.7 install bundled with Lion, the library doesn't come with .py source files. That directory contains .pyc and .pyo files, but no .py files. virtualenv doesn't seem to expect that.
My workaround is to download Python 2.7 source:
http://python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
and unpack distutils/__init__.py into the expected place:
sudo tar xvjf ~/Downloads/Python-2.7.2.tar.bz2 --strip-components=2 -C /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 Python-2.7.2/Lib/distutils/__init__.py
That permits virtualenv to complete successfully, and the resulting Python interpreter seems to run.
Given that the Python 2.7 library bundled with Lion is installed without source, it might seem useful to change virtualenv to try for either distutils/__init__.py or distutils/__init__.pyc ?
> cd /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/
> sudo touch __init__.py
Out-of-the-box python on Lion comes without the python source - just the compiled pyc/pyo files. However virtualenv goes looking for the distutils source file just to confirm where it is. Turns out all we need to do it touch the file it's looking for into existence.
Credits belong to "npdoty" and "Nat Goodspeed".
Turns out the problem was that Migration Assistant, for whatever reason, didn't copy over tools like gcc -- I reinstalled Xcode and things work properly again.
While Migration Assistant doesn't handle things like XCode so well, it is nevertheless designed to transfer some types of applications. It works best with those that exist entirely in the /Applications/ folder or those applications that launch from the /Applications/ folder and do checks for associated files located elsewhere (e.g., /usr/bin/), installing them when they aren't detected on startup.
See http://support.apple.com/kb/HT4413.
I have used a similar approach of Nat Goodspeed.
But I've copied all *.py files.
Download the same version of your system python, 2.7.2 in my case:
$ python --version
Download it and unpack it.
http://python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
# -n copy only missing files, -r recursively
$ sudo cp -rn ~/Downloads/Python-2.7.2/Lib/* /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
Related
I am trying to install Anaconda3-2019.10-Windows-x86_64.exe on window 8.1. During installation, I checked details and there seemed have many issues.
No Scripts folder or Conda Command prompt or shortcuts were created.
Only conda-meta, Lib, pkgs,_conda.exe and Uninstall-Anaconda3.exe are created.
I tried 32 bits also and miniconda versions. All of them don't work for me. I already tried multiple uninstallation and installation. But the result is the same.
any inputs will be very helpful.
Extract: anaconda-2019.10-py37_0.tar.bz2 [7424] Failed to execute
script conda.exe
Traceback (most recent call last): File
"site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 149,
in init File "ctypes__init__.py", line 348, in init
OSError: [WinError 126] The specified module could not be found
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "conda.exe.py", line 45, in
File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line
151, in init
main.PyInstallerImportError: Failed to load dynlib/dll 'C:\Users\USERNAME\AppData\Local\Temp\_MEI77242\archive.dll'.
Most probably this dynlib/dll was not found when the application was
frozen.
Traceback (most recent call last): File
"site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 149,
in init File "ctypes__init__.py", line 348, in init
OSError: [WinError 126] The specified module could not be found
Finally, I used 64 bit preview version of installer from from 2020 Feb. The installation was completed successfully now and everything is working fine. I suspect there is issue with 2019.10 verion which might have caused problems.
Thanks to the github conda issues page which leads to this solution.
Make sure to check hash values of your installer just for in case too.
For me, it's the opposite. When i used the installers from 2020, Anaconda is installed in C:\Users\username\Anaconda3. This gives me the same problem as you with no Scripts folder, no command prompt, no Anaconda Navigator. I tried the 2019 version and now Anaconda is installed in C:\Users\username\AppData\Local\Continuum\anaconda3 and it works.
Maybe changing the install path for the 2020 versions would have worked too. I didnt try it though. I have Windows 10 and used the x86_64 files.
This issue can be eradicated by uninstalling the current version of conda and install the previous version of anaconda anaconda 2019.03. It will help solve the issue.
This problem still exists in Anaconda3 2021.11. I suspect the problem is in the username (might be that this occurs only with certain localizations). If the username has special characters or space the AppData/Local/Continuum folder will simply be missing. What is unacceptable is the installer telling the installation was a success.
If you install it globally you will still not be able to use it when you create a new enviroment (It tries to put it in the user folder, succeeds, then doesn't find anything when eg. you try to install new packages to this env). (This might be dependent on other localization settings too)
Solution is to create a simple user folder like instead of Kovács Xaviér make it KovacsXavier (I'm sure the Caps doesn't bother it). Now you will be able to install it.
If you have a new windows installation you can trick windows into creating such a short username by adding this as your "UserName" first and later renaming yourself. The directory created will remain the same but you can rename your displayed name later. I really doesn't recommend anyone letting Windows create a fancy named home folder. Not anaconda is the only software that has problems with this.
Another notable observation that you better leash your antivirus software when installing Anaconda.
But it is obvious Anaconda doesn't check software integrity after install. Which is sad.
Global search for the file .condarc in the drive you installed in. Uninstall anaconda and delete .condarc file. Reinstall Anaconda and you should be good to go. Was stuck with this problem for hours, hope this helps!
From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.
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 want to try to develop Cocoa application using Python. I'm new to Mac and I need some help to understand how it works.
First of all I found that I need to install py2app and py2objc. I used easy_install as documented here. There were a few errors with setup tools but eventually py2app was installed. Then I launch "easy_install pyobjc==2.2" and it ended with many errors:
Processing pyobjc-2.2-py2.7.egg
...
Running pyobjc-framework-SystemConfiguration-2.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ipMzFU/pyobjc-framework-SystemConfiguration-2.2/egg-dist-tmp-odfVol
In file included from Modules/_manual.m:1:
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:19:20: error: limits.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:22:2: error: #error "Something's broken. UCHAR_MAX should be defined in limits.h."
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:26:2: error: #error "Python's source code assumes C's unsigned char is an 8-bit type."
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:33:19: error: stdio.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:35:5: error: #error "Python.h requires that stdio.h define NULL."
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:38:20: error: string.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:40:19: error: errno.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:42:20: error: stdlib.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:44:20: error: unistd.h: No such file or directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:56:20: error: assert.h: No such file or directory
...
etc
My questions:
What I need to do to install
py2objc? Unfortunately, I haven't
found a solution for errors, which I
posted previously.
As I understand
there are two kinds of python. One I
installed into Applications folder
(IDLE, launcher), another is the
current Python version supplied with
OS. Can you describe the
difference?
How can I select the
current version of Python used by
Mac OS? And what is the Current
folder in
/Library/Frameworks/Python.framework?
Probably it looks confusing, but this is my first steps! :)
Thank you
Cannot give a definitive answer to that. See comment.
You can install multiple versions of python on your machine (OSX includes a defualt one as you already mentioned). In the applications folder there are some apps to open an interactive interpreter in which you can enter python commands, such as IDLE. These applications use one of the python versions you've got installed. Which brings us to
python_select is the command you want. e.g. python_select -l to list all the python versions you've got installed and python_select python27 to select your own 2.7 version. The Current folder links to the version currently selected via python_select
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