I have used miniconda and pip to download modules such as matplotlib. The modules works fine when I work in command prompt, but doesn't work when I try to import in my IDLE 3.5 version
It's possible that your command prompt is using a different version of Python. I know that may not be the case, but there is a difference between python, python2, python3, and even more changes in a virtualenv.
In your command prompt (where the module works), type in python, and try to import your module. If it works, check what version of you are using.
For instance, here is what happens when I type in python3 into my terminal.
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
From that, you can see I am using Python 3.4.3.
Now in IDLE, confirm that the versions match, if they do not, then you can work to solving the problem.
Problem still persisting?
You may have two versions (somehow) in different locations. Open up the command prompt and IDLE and type these 3 commands in each
import sys
sys.version
sys.path
Make sure sys.path is the same in both.
I hope I helped!
Related
My Pillow installation is broken system-wide.
Either using my OS X pillow version, or other 'isolated' installations within anaconda environments, I always get the same error, while trying to process images:
AccessInit: hash collision: 22 for both 1 and 1
It used to work in the envs, but after some urllib installs it broke in the environments also.
I have tried, at the top of my script (to no avail):
import PIL.Image
sys.modules['Image'] = PIL.Image
from PIL import Image
I have already uninstalled an reinstalled Pillow, again to no avail.
my Python:
Python 2.7.14 |Anaconda, Inc.| (default, Oct 5 2017, 02:28:52)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
How can I make it work again?
Your problem is likely that two different Python modules are being imported with the same name - https://web.archive.org/web/20110121072135/https://jaredforsyth.com/blog/2010/apr/28/accessinit-hash-collision-3-both-1-and-1/
Without having access to your installation, it is hard to figure out exactly what is happening, so I would suggest tracking each import. A good start would be to see what is imported.
import sys
sys.modules
That, combined with going into the site-packages directory of your Python install and manually removing packages until you find the problematic package, will hopefully give you a good start.
OSX. When I installed the Canopy IDE, Enthought Canopy Python 2.7.6 was set as the default Python for the bash shell:
$ python
Enthought Canopy Python 2.7.6 | 32-bit | (default, Sep 15 2014, 17:36:57)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Currently, I am using another IDE (PyCharm) for a project where a Python module is needed. I tried to download the module directly from the bash shell using pip but it did not work:
pip install psycopg2 <---module
I believe it has something to do with Enthought Canopy Python running, so I attempted to restore the original python. However, I could not restore it. The instructions from this Enthought post (2011) did not work:
OS X - After EPD installation, restore system python to be default
They say to comment out the following lines from the ~/.bash_profile file, save the changes and restart the bash shell:
# PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
# export PATH
Didn't work.
All seems to work just fine for both python 2 and 3:
$ which Python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ python --version
Python 2.7.9
$ python2
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
$ python3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
My .bash_profile settings are as follows:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
The problem:
$ virtualenv My_Env
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python3/bin/python3.4: bad interpreter: No such file or directory
The path above does not exist. I downloaded my python packages directly from the python site and installed using the default settings.
Prior to this, I used Python installed with HomeBrew, but this path does not appear to be a brew file path anyway.
Bottom line... My file path is messed up somewhere other than in my .bash_profile and I have no idea where to look to fix it.
Also note that I set up my other computer with the same exact .bash_profile and python installations and it works perfectly...
Both are running Mac Yosemite.
Thanks in advance!
Ok, I was able to fix the problem with a fresh install of virtualenv. I assume that is where the path issue was located (somewhere in the installation of virtualenv).
My problem was as simple as having spaces in the directory at the top of venv/bin/pip which meant that the path was inside quotes. As soon as I made sure that it wasn't under a directory with spaces and removed the quotes it worked.
eg. #!"/Users/Tomm/MY PROJECT/venv/bin/python" should be changed to #!/Users/Tomm/MY-PROJECT/venv/bin/python
You can check the "activate" file in your virtualenv bin folder, and see what is written there at around line 42, and then can actually manually set it, while keeping in mind that all the executables in this bin folder are hard coded for the first shebang line.
You will need to change them as well. Or just move the folder to the right place for you current temporary task, otherwise you might need a virtualenv relocation tool or just re-install it.
Re-installing virtualenv should solve this. I also went through same bug and reinstalling using pip solved this for me.
I've installed python27 on my MacBook Pro (OS X 10.6.8) using Macports. Here is the output for sudo port select --list python:
Available versions for python:
none
python25-apple
python26-apple
python27 (active)
But when I type the python command, it's running python26:
rod:~ $python
Python 2.6.6 (r266:84292, Feb 11 2012, 09:09:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
I've tried uninstalling my Macports pythons (I used to have the python31 and python25 macports as well) and reinstalling, but to no avail.
I should note that I recently had to do a time machine restore due to a hard drive failure, and I've been finding that some of the soft links seem not to have restored properly. I wonder if this could be a source of my problems here. Any tips?
Does your .profile still have the /opt/local paths prepended to $PATH? If its not present then despite being selected you wont get it by default because it symlinks the version to /opt/local/bin/python
Hi there I have downloaded the mac installer here, http://www.python.org/download/releases/3.1.2/ , & installed it. But when I run terminal & type python it says:
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
What I want to know is, is it safe to run Update Shell Profile.command in the Python 3.1 folder ? or should I run python 3.1.2 separately ? If I should run python 3.1.2 separately, how do I do so ? also how do I start IDLE ?
Is there another python executable, perhaps python31?
You can also install other python versions via MacPorts if you need (although you'll still have to choose the right executable).
This should also be relevant: Multiple versions of Python on OS X Leopard