OSX installing numpy via brew for python3 - python

I can't install numpy for python3 via brew.
I type:
brew install numpy --with-python3
then it's OK for python2
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 numpy
>>>
but still not found for python3
Python 3.4.0 (v3.4.0:04f714765c13, Mar 15 2014, 23:02:41)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'numpy'
>>>
How to make it work for python3 ?

The correct way to install it is via:
pip3 install numpy
Obviously, you need to install python3 and pip first. I tested and works without any problem.

The problem with the Homebrew is that it sees only the system's python and the one it installed itself. So you have to first install python3 via brew and then use the --with-python3 option.

Related

import opencv with anaconda using python package

I'm currently working on a project with anaconda. I was able to install opencv-python with the regular pip3 install (not anacondas version). When I import cv2, its successful.
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
If I copy that package into my anaconda path, and run python with anaconda, import cv2 I get the following error:
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
Is there a way to get around this without using the Anacondas pip install? I don't have internet on the machine I'm working on. I've done this method with other packages and it has worked fine, not with opencv.

How do I install shogun's python interface?

I'm on a Mac. Step 1:
sudo conda install -c conda-forge shogun
Step 2:
$ python
Python 2.7.12 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import shogun
>>> from shogun import RealFeatures, PolyKernel, CSVFile
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name RealFeatures
I also tried on Fedora using the RPMs. After verifying that the C++ interface works (gcc shogun.cpp -I/usr/include/shogun/base -lshogun -L/usr/lib64/libshogun.*) I followed the instructions here and set PYTHONPATH=/usr/lib64/python2.7/site-packages/modshogun.py
And then:
$ python
Python 2.7.13 (default, May 10 2017, 20:04:36)
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shogun
>>> from shogun import RealFeatures, PolyKernel, CSVFile
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name RealFeatures
The problem here is probably that shogun's docs are currently for the in-development version 6.1, but the conda package is for the latest actual release 6.0. In 6.0, you need to do from modshogun import RealFeatures; the shogun package is the old interface, and the modern "modular" one is modshogun. This will be renamed to just shogun in the upcoming 6.1 release.

How do I get Python to see libtorrent-rasterbar in mac os?

I try to install libtorrent-rasterbar, but Python does not see the module. The El Captaine system. Tell me where to look?
andrew: ~ $ brew install python3
Warning: python3-3.6.0_1 already installed
andrew: ~ $ brew install libtorrent-rasterbar
Warning: libtorrent-rasterbar-1.1.1 already installed
andrew: ~ $ python
Python 3.6.0 (default, Mar 4 2017, 12:32:37)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import libtorrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'libtorrent'
>>>
For python2 it work: https://gist.github.com/jacobzelek/ecb6e98feb91d911e231
May be for python3 is similarly

Python Module not found error even when the module is installed

When I try to import the Image module, it fails to find the module.
nn-MacBook-Pro-3:~ nn$ 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 Image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Image
>>>
Pip list shows that it is installed.
nn-MacBook-Pro-3:~ nn$ pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
appnope (0.1.0)
bleach (1.5.0)
cycler (0.9.0)
dask (0.13.0)
decorator (4.0.11)
distribute (0.7.3)
Django (1.10.5)
email (6.0.0a1)
entrypoints (0.2.2)
Flask (0.10.1)
html5lib (0.9999999)
image (1.5.5)
I'm using Mac's default python version.
nn-MacBook-Pro-3:~ nn$ 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.
>>>
The PYTHONPATH variable seems to be empty, but when I try to import other already installed packages it does not show the "no module found" error.
nn-MacBook-Pro-3:~ nn$ echo $PYTHONPATH
I have also tried everything stated here, but it didn't work for me.
Update
As Suggested that modules are case sensitive, I tried the following, it but didn't work either.
nn-MacBook-Pro-3:~ nn$ 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 image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named image
you need to do import image instead of import Image
module names are case-sensitive

Error with pylibmc on Mac OS Lion

I have a problem with pylibmc on Mac OS Lion.
libmemcached — 1.0.4
pylibmc — 1.2.3
$ python
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylibmc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/pylibmc/__init__.py", line 70, in <module>
import _pylibmc
ImportError: dlopen(/Library/Python/2.7/site-packages/_pylibmc.so, 2): Symbol not found: _memcached_add
Referenced from: /Library/Python/2.7/site-packages/_pylibmc.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/_pylibmc.so
But it works with sudo!
$ sudo python
Password:
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylibmc
>>>
Any ideas?
Installation in 32-bit mode solved the problem.
You need to install libevent in 32-bit mode
brew install --universal libevent
Next to download libmemcached source (1.0.8 version works for me) and configure force for 32 bit arch:
./configure --build=i386-apple-darwin11.4.2 "CFLAGS=-m32" "CXXFLAGS=-m32" "LDFLAGS=-m32"
make
sudo make install
where 11.4.2 is the version of kernel
Reinstall pylibmc
sudo pip uninstall pylibmc
sudo pip install pylibmc
Now it works
$ python -c 'import pylibmc'
$
Looks like a build and/or installation problem with libmemcached. Maybe you can check out issue #101? https://github.com/lericson/pylibmc/issues/101

Categories

Resources