Mac - running python with sudo makes it get wrong libraries - python

I'm trying to install pycuda on my mac machine.
Problem is, when I run python with sudo, it gets the wrong version for python-six, which is required by pycuda.
How can I fix this?
Jean-Lucs-MacBook-Pro:test Jean$ sudo python
Password:
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.get_distribution("six").version
'1.4.1'
>>> import six
>>> print six.__file__
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc
>>>
Jean-Lucs-MacBook-Pro:test Jean$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.get_distribution("six").version
'1.9.0'
>>> import six
>>> print six.__file__
/usr/local/lib/python2.7/site-packages/six.pyc
>>>

Related

Python: how to have both python 2 and python 3 on jupyter on mac?

I am running jupyter on mac
If I choose python3 and I import a package that works only on python3 I have the following:
However If I do:
python3
Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:10:22)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mgwr
it works fine

Difference between enum behavior with Python

Here's Python 2.7.6 on my Ubuntu laptop:
(myenv)$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> class Fruit(enum.Enum):
... apple=1
... orange=2
...
>>> Fruit.apple
<Fruit.apple: 1>
>>> type(Fruit.apple)
<enum 'Fruit'>
and here's it on Heroku (also 2.7.6):
~ $ python
Python 2.7.6 (default, Jul 15 2014, 15:38:10)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> class Fruit(enum.Enum):
... apple=1
... orange=2
...
>>> Fruit.apple
1
>>> type(Fruit.apple)
<type 'int'>
EDIT: My requirements.txt file contains this line:
enum==0.4.4
This is legitimately causing issues as my production version exhibits bugs the local version does not!
Looks like your ubuntu version is the enum34 backport, while the heroku version is the older enum package.
If I read your question correctly and the version with enum34 is working properly, change your requirements file to use it instead.
Check the versions of enum library. In your env there is probably older and deprecated version. Anyway field inside enum class must be of its declared type, which in your case is int.
... apple=1
... orange=2
and type of
fruit = Fruit
would be Fruit
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> enum.__version__
'0.4.4'
Try checking enum.__version__.

Caffe import working with python2 but not python2.7 / ipython notebook, despite both being 2.7.10?

I've successfully compiled the caffe library and the python module.
I can do this:
Jamess-Air:~ james$ python2 -V
Python 2.7.10
Jamess-Air:~ james$ python2
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>>
But, bizarrely, this fails:
Jamess-Air:~ james$ python2.7 -V
Python 2.7.10
Jamess-Air:~ james$ python2.7
Python 2.7.10 (default, Jun 19 2015, 15:39:31)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
Segmentation fault: 11
Jamess-Air:~ james$
I cannot understand this at all! Whenever I try to run using iPython notebook I get the same crash.
Any ideas as to what may be causing this, and how I might fix it, or at least get iPython Notebook to use the different python version so I can run this thing?
Thanks!

Python "Segmentation fault: 11" when running "import cv" or "import cv2"

I have installed numpy and opencv using macports as per these instructions, but when I try import cv or import cv2 I just get the segfault and I have no idea why.
Any suggestions?
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
Segmentation fault: 11
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Segmentation fault: 11
Sorry there are so few details, but this is a new computer and I installed macports on it just for this, and these are the only things I've installed with macports, so I have no idea why this isn't working.
Edit: Now I'm More Confused.
Looking through the crash report I found this:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
So, as a shot in the dark, I ran python as super user:
$ sudo python
Python 2.7.9 (default, Dec 13 2014, 15:13:49)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
>>>
As super user, everything appears to run fine. How is this possible?
If you look closely to the info message of your python command, you will see the difference.
From the buggy one:
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Segmentation fault: 11
From the working one:
$ sudo python
Python 2.7.9 (default, Dec 13 2014, 15:13:49)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
>>>
You have two different versions of Python on your machine which might explain the behaviors you got.
After hitting this problem on OSX 10.11 and trawling through several cases of this problem in various contexts, I realized that this problem happens due to following independent reasons mostly:
conflicting python versions (more than one pythons); solution - uninstall one of them, get the one thats compatible with opencv ("Segmentation fault" during "import cv" on Mac OS)
opencv version issue; solution - get the right version for you Python opencv feature detector causes segmentation fault
issue with your numpy version; solution - uninstall and install numpy again (OpenCV - cannot find module cv2)
I tried all 3 but number 3 solved my issue.
Using
cv2.ocl.setUseOpenCL(False)
at the beginning of the code solved the problem for me.
For me the solution was simply
sudo apt install python3-opencv
and then install pip opencv package
sudo pip3 install opencv-python
or
sudo pip install opencv-python
Note: This was because I have launched a new Aws instance.
I encountered the similar problem.
➜ ~ ✗ python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
[1] 41233 segmentation fault python
But if I import numpy first, the problem will go away.
➜ ~ ✗ python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import cv2
>>>

Python 2.7.3 not working in Mavericks Terminal :(

so i upgraded to Mavericks hoping that my scripts would be fine . . . luckily when I run my scripts in Coderunner they work . i do simple test scripts in the terminal because its easy and i like the way it looks. i'm not sure why the frameworks work in coderunner but not the terminal.
does anyone have any idea how to fix this ?
i tried updating the software and got the same error
Last login: Wed Oct 30 11:08:51 on ttys000
opus-magnum:~ Opus_Magnum$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> s = 'hello'
>>> print s
Segmentation fault: 11
opus-magnum:~ Opus_Magnum$
`
You are not running the correct version of python that was released with OS X Mavericks.
[1:17pm][wlynch#watermelon ~] /usr/bin/python2.7
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Categories