Python 3.3 cannot find any pip installed package on OSX? - macos

I recently installed the Python 3.3 DMG from Python.org.
I have pip, virtualenv, and virtualenv-wrapper installed.
When I do:
$ mkvirtualenv -p /usr/local/bin/python3 someenv
The environment gets created as expected.
When I then do a pip install, like say:
(someenv) $ pip install beautifulsoup4
It installs correctly (no errors).
When I then fire up python:
(someenv) $ python
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'bs4'
I've also tried a few other packages: pytz, pymemoize, mock, and all seem to suffer from the same "No module named ..." problem.
Looking in the virtual environment's site-packages directory, the packages are there, it's just that the interpreter cannot seem to find them. If I do a pip freeze all installed packages are listed.
Any suggestions?
If it helps, I'm using:
Python 3.3 (again, installed from the .dmg at Python.org)
pip v1.2.1
virtualenv-wrapper v1.8.2
distribute 0.6.28
OSX 10.7 (Lion)
Edit: as requested, the output of sys.path is:
['', '/Library/Frameworks/Python.framework/Versions/3.3/lib/python33.zip',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages']
And as such what is missing is: `/Users/aparkin/.envs/someenv/lib/python3.3/site-packages' -- the virtual environment's site-packages directory.
Edit 2: as well, doing an ls -l on the site-packages directory gives:
$ ls -l .envs/someenv/lib/python3.3/site-packages/
total 168
drwxr-xr-x 7 aparkin staff 238 18 Oct 11:49 PyMemoize-0.1.1-py3.3.egg-info
drwxr-xr-x 3 aparkin staff 102 18 Oct 11:51 __pycache__
drwxr-xr-x 7 aparkin staff 238 18 Oct 11:34 beautifulsoup4-4.1.3-py3.3.egg-info
drwxr-xr-x 9 aparkin staff 306 18 Oct 11:32 bs4
drwxr-xr-x 8 aparkin staff 272 18 Oct 11:31 distribute-0.6.28-py3.3.egg
-rw-r--r-- 1 aparkin staff 237 18 Oct 11:31 easy-install.pth
drwxr-xr-x 6 aparkin staff 204 18 Oct 11:49 memoize
drwxr-xr-x 7 aparkin staff 238 18 Oct 11:51 mock-1.0.0-py3.3.egg-info
-rw-r--r-- 1 aparkin staff 75204 18 Oct 11:51 mock.py
drwxr-xr-x 4 aparkin staff 136 18 Oct 11:31 pip-1.2.1-py3.3.egg
drwxr-xr-x 9 aparkin staff 306 18 Oct 11:44 pytz
drwxr-xr-x 8 aparkin staff 272 18 Oct 11:44 pytz-2012f-py3.3.egg-info
-rw-r--r-- 1 aparkin staff 30 18 Oct 11:31 setuptools.pth

A new feature of Python 3.3 is a standard way to create and manage virtual environments, pyvenv. You should use it instead.
That said, you still should be able to make the old virtualenv work. One thing to check is the value of sys.path when using the virtualenv python that fails. You should see the virtualenv site-packages directory on it. If so and imports still don't work, check the virtualenv lib directories including site-packages for the correct file permissions.
Update: The contents of virtualenv site-packages looks reasonable at first glance. But the value of sys.path looks suspiciously like that of the standard python3.3, not one running from a virtualenv. So check to make sure you really are using that one. Try running the virtualenv python with an absolute path, like:
/path/to/someenv/bin/python3.3 -c 'import sys;print(sys.executable);print(sys.path)'
Also make sure you have no Python-related environment variables set, like PYTHONPATH or shell aliases or functions for python.
env | grep PYTHON
echo $PATH
which python
type python

I think it is because you set an alias for python in your terminal.
If you use zsh, just use an editor (e.g vim) to open ~/.zshrc, and delete the alias for python, and then run source ~/.zshrc in your terminal or close the terminal windows and reopen it.
If you don't use zsh, the principle is the same, just delete the alias.
This will solve your problem.

Related

Error while trying to install virtualenv for OpenCV for Python 3.6.5 on Mac OS Catalina

I get the following error when I am trying to install virtualenv and virtualenvwrapper:
source ~/.bash_profile
/usr/local/bin/python3
/usr/local/opt/python/bin/python3.6: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON =/usr/local/bin/python3 and that PATH is
set properly.
My bash profile is as follows:
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH
# add custom, local installations to PATH
PATH=/usr/local/bin:/usr/local/sbin:"$PATH"
# add MacPorts to PATH
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/
source /usr/local/bin/virtualenvwrapper.sh
and my PATH is:
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
I see that the virtualenv and virtualenvwrapper.sh are present in /usr/local/bin
This shows that i have the "virtualenv" installed in the following directory.
MacBook-Air:bin jays$ ls -alt vir*
-rwxr-xr-x 1 root admin 301 Jul 8 22:09 virtualenv-clone
-rwxr-xr-x 1 root admin 325 Jul 8 22:09 virtualenv
-rwxr-xr-x 1 root admin 41703 Feb 9 2019 virtualenvwrapper.sh
-rwxr-xr-x 1 root admin 2210 Feb 9 2019 virtualenvwrapper_lazy.sh
MacBook-Air:bin jays$ pwd
/usr/local/bin
This is the directory listing to show my python directory:
MacBook-Air:bin jays$ ls -alt pyt*
I have python 3.6.5:
lrwxr-xr-x 1 jays admin 46 Jul 8 21:38 python3.6m-config -> ../Cellar/python/3.6.5_1/bin/python3.6m-config
lrwxr-xr-x 1 jays admin 39 Jul 8 21:38 python3.6m -> ../Cellar/python/3.6.5_1/bin/python3.6m
lrwxr-xr-x 1 jays admin 45 Jul 8 21:38 python3.6-config -> ../Cella
r/python/3.6.5_1/bin/python3.6-config
lrwxr-xr-x 1 jays admin 38 Jul 8 21:38 python3.6 -> ../Cella
r/python/3.6.5_1/bin/python3.6
lrwxr-xr-x 1 jays admin 43 Jul 8 21:38 python3-config -> ../Cellar/python/3.6.5_1/bin/python3-config
lrwxr-xr-x 1 jays admin 36 Jul 8 21:38 python3 -> ../Cellar/python/3.6.5_1/bin/python3
Any insight would be appreciated. I looked at similar questions which have been answered however the answers there did not resolve my issue.

How to run a OSX application with OpenCV in a mac without OpenCV installed

I am developing a OSX application in Objective-C and OpenCV-2.4.12 using Xcode.
I followed this installation video guide and this setup video guide to integrate the OpenCV. Basically in the second video, the author uses the OpenCV dynamic libraries (.dylib files).
This work perfectly in my mac, but in another macs without OpenCV installed the application gives an error and I can´t open and run it.
I have searched and I think the solution is to use static libraries (.a files). But I can´t figure out how to replace the dynamic libraries with static libraries.
Which static libraries I need to use? Where I find them? How I link them in Xcode?
My settings right now:
I added to the project the libopencv_core.2.4.12.dylib, libopencv_highgui.2.4.12.dylib, libopencv_imgproc.2.4.12.dylib.
In the Search Paths I have (like explained in the second video):
Framework Search Paths: /usr/local/lib
Header Search Paths: /usr/local/include
Library Search Paths: "OpenCVFolderPath"/build/lib
Thank you.
I tend to install OpenCV using homebrew and if I look at the options I can specify for OpenCV Version 3 like this:
brew options opencv3
I get this output:
--32-bit
Build 32-bit only
--c++11
Build using C++11 mode
--with-contrib
Build "extra" contributed modules
--with-cuda
Build with CUDA v7.0+ support
--with-examples
Install C and python examples (sources)
--with-ffmpeg
Build with ffmpeg support
...
...
--with-python3
Build with python3 support
--with-qt
Build the Qt4 backend to HighGUI
--with-qt5
Build the Qt5 backend to HighGUI
--with-quicktime
Use QuickTime for Video I/O instead of QTKit
--with-static <--- *** HERE ***
Build static libraries
--with-tbb
Enable parallel code in OpenCV using Intel TBB
--with-vtk
Build with vtk support
--without-eigen
Build without eigen support
--without-numpy
Use a numpy you've installed yourself instead of a Homebrew-packaged numpy
--without-opencl
Disable GPU code in OpenCV using OpenCL
--without-openexr
Build without openexr support
--without-python
Build without Python support
--without-test
Build without accuracy & performance tests
--HEAD
Install HEAD version
So, if I then go ahead and install like this:
brew install opencv3 --with-static
I end up with these static libraries which look like what you want:
ls -l /usr/local/Cellar/opencv3/3.1.0_3/lib/
-r--r--r-- 1 mark admin 1922864 21 Jul 14:23 libopencv_calib3d.a
-r--r--r-- 1 mark admin 3215896 21 Jul 14:23 libopencv_core.a
-r--r--r-- 1 mark admin 965336 21 Jul 14:23 libopencv_features2d.a
-r--r--r-- 1 mark admin 650552 21 Jul 14:23 libopencv_flann.a
-r--r--r-- 1 mark admin 60016 21 Jul 14:23 libopencv_highgui.a
-r--r--r-- 1 mark admin 378128 21 Jul 14:23 libopencv_imgcodecs.a
-r--r--r-- 1 mark admin 3946248 21 Jul 14:23 libopencv_imgproc.a
-r--r--r-- 1 mark admin 954296 21 Jul 14:23 libopencv_ml.a
-r--r--r-- 1 mark admin 542808 21 Jul 14:23 libopencv_objdetect.a
-r--r--r-- 1 mark admin 1078504 21 Jul 14:23 libopencv_photo.a
-r--r--r-- 1 mark admin 269248 21 Jul 14:23 libopencv_shape.a
-r--r--r-- 1 mark admin 694056 21 Jul 14:23 libopencv_stitching.a
-r--r--r-- 1 mark admin 193416 21 Jul 14:23 libopencv_superres.a
-r--r--r-- 1 mark admin 478776 21 Jul 14:23 libopencv_video.a
-r--r--r-- 1 mark admin 149040 21 Jul 14:23 libopencv_videoio.a
-r--r--r-- 1 mark admin 390288 21 Jul 14:23 libopencv_videostab.a
drwxr-xr-x 3 mark admin 102 21 Jul 14:23 pkgconfig
drwxr-xr-x 3 mark admin 102 21 Jul 14:23 python2.7
There doesn't appear to be an equivalent option with OpenCV2, though I am not sure why you would want to use that version.

Yosemite upgrade broke ruby.h

Ever since upgrading to Yosemite, I get this error trying to build anything that includes ruby.h:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
^
1 error generated.
make[1]: *** [objects/if_ruby.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [first] Error 2
And sure enough, /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/config.h is indeed missing.
$ ls -laF /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/
total 72
drwxr-xr-x 21 root wheel 714 Jul 29 21:56 ./
drwxr-xr-x 5 root wheel 170 Jul 29 21:56 ../
drwxr-xr-x 7 root wheel 238 Jul 29 21:56 backward/
-rw-r--r-- 2 root wheel 3360 Sep 21 15:25 debug.h
-rw-r--r-- 2 root wheel 5553 Sep 21 15:25 defines.h
-rw-r--r-- 2 root wheel 881 Sep 21 15:25 digest.h
-rw-r--r-- 2 root wheel 7628 Sep 21 15:25 dl.h
-rw-r--r-- 2 root wheel 14123 Sep 21 15:25 encoding.h
-rw-r--r-- 2 root wheel 32904 Sep 21 15:25 intern.h
-rw-r--r-- 2 root wheel 5869 Sep 21 15:25 io.h
-rw-r--r-- 2 root wheel 4522 Sep 21 15:25 missing.h
-rw-r--r-- 2 root wheel 37617 Sep 21 15:25 oniguruma.h
-rw-r--r-- 2 root wheel 1502 Sep 21 15:25 re.h
-rw-r--r-- 2 root wheel 890 Sep 21 15:25 regex.h
-rw-r--r-- 2 root wheel 49734 Sep 21 15:25 ruby.h
-rw-r--r-- 2 root wheel 4651 Sep 21 15:25 st.h
-rw-r--r-- 2 root wheel 374 Sep 21 15:25 subst.h
-rw-r--r-- 2 root wheel 1102 Sep 21 15:25 thread.h
-rw-r--r-- 2 root wheel 2139 Sep 21 15:25 util.h
-rw-r--r-- 2 root wheel 1968 Sep 21 15:25 version.h
-rw-r--r-- 2 root wheel 1794 Sep 21 15:25 vm.h
Did the install accidentally a file? Does Yosemite just ship with a busted Ruby header file set?
What's the best way to fix this? Can I just unpack the source code in there to get the right headers?
One note on this: I ran into this problem after upgrading to "OS X El Capitan". I installed the command line tools by running 'xcode-select --install'. After that, my ruby build environment started working again.
For those who already had Xcode installed from the Apple developers site, running xcode-select --install doesn't work, since it will say that Xcode is already installed (Xcode already comes with the CommandLineTools bundled).
In my case, I fixed it by downloading the corresponding CommandLineTools from the same place, executing it, then going to /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg and executing it too.
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby
sudo ln -s ../universal-darwin15/ruby/config.h ./config.h
updates Nicholas Tsipanov's answer from 2014-10-18.
I got the same error, but installed "Command Line Tools (OS X 10.10) for Xcode - Xcode 6.1" and installing worked fine after that.
If you use Homebrew, brew install ruby is a fast workaround (it gets you a brand new ruby installation distinct from the one from Xcode).
Try this:
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby
sudo ln -s ../universal-darwin13/ruby/config.h ./config.h
Xcode got messed up in the upgrade somehow.
I opened Xcode (which I never do otherwise) and it complained about all sorts of missing components. So I let it go ahead and fix itself, and now all is well.
Props to CDub in the comments on OP for pointing to this as a potential source of weirdness.
I am running Mojave 10.14.6. The answer here fixed the subject issue for me: https://stackoverflow.com/a/58084238/284651
Solution:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
sudo xcodebuild -license accept
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Fixed by pointing to correct path for Xcode developer tools.
Error before (Note the path to Xcode711.app instead of Xcode.app)
/Applications/Xcode711.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/ruby.h:24:10:
Ran
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Failed to install PyZMQ 13.1 for PyPy 2.0.2 on Ubuntu 12.04.2 LTS

I use pip install as root. Everything works with CPython because it doesn't use the cffi backend. With PyPy I get the following error:
ImportError: PyZMQ CFFI backend couldn't find zeromq: [Errno 2] No such file or directory:
'/********/site-packages/zmq/cffi_core/__pycache__/_cffi__g5368a726x67d4e236.c'
The '/**/site-packages/zmq/cffi_core/ directory exists and contains the following .py files(and correponding .pyc):
-rw-r--r-- 1 root 7.8K Jul 16 17:29 _cffi.py
-rw-r--r-- 1 root 406 Jul 16 17:29 constants.py
-rw-r--r-- 1 root 2.2K Jul 16 17:29 context.py
-rw-r--r-- 1 root 915 Jul 16 17:29 devices.py
-rw-r--r-- 1 root 551 Jul 16 17:29 error.py
-rw-r--r-- 1 root 1000 Jul 16 17:29 __init__.py
-rw-r--r-- 1 root 1.7K Jul 16 17:29 message.py
-rw-r--r-- 1 root 2.1K Jul 16 17:29 _poll.py
-rw-r--r-- 1 root 6.8K Jul 16 17:29 socket.py
-rw-r--r-- 1 root 1.1K Jul 16 17:29 stopwatch.py
But, there is no __pycache__ directory.
By poking around the cffi Python files (in particular verifier.py) I found that it can't find the following cffi_g5368a726x67d4e236.pypy-20.so. I couldn't find it anywhere either. I guess it is not built for some reason, but I didn't see any errors during pip install.
Does anyone have any idea?

Lilypond Mac OS X build issue

I am trying to do a clean build of Lilypond on a clean install of Mac OS X. Dependencies have been installed using Brew.
I do ./configure && make all in the Lilypond dir. It gets through the configure and starts building but ends on
ERROR: In procedure dynamic-link:
ERROR: file: "libguile-srfi-srfi-1-v-3", message: "file not found"
I know what libguile is, I don't know if it's on my system (or where it ought to be) but the configure script completes successfully and does not identify it as a missing dependency so I assume it was able to find it.
Any suggestions? Googling shows some old hints with regards to setting $LD_LIBRARY_PATH, but it seems these don't apply to Mac OS 10.6.
There is a port of lilypond available from MacPorts.
$ port info lilypond
lilypond #2.12.3, Revision 3 (textproc)
Variants: [+]docs, gui, universal
Description: Lilypond is a unix-based automated engraving system that generates beautiful sheet music from input files. Lilypond uses its
own input format, .ly, which in many ways is similar to LaTeX. Lilypond can export sheet music to PDF, EPS, SVG, and PNG
formats, and can also create MIDI files.
Homepage: http://lilypond.org/
Library Dependencies: fontforge, ghostscript, mftrace, guile, texinfo, pango, flex, urw-fonts, netpbm
Platforms: darwin
License: unknown
Maintainers: snc#macports.org, openmaintainer#macports.org
It's likely that the dynamic libraries have a .dylib extension, but need a .so extension.
I worked around this by creating links in /opt/local/lib
Owner-Users-MacBook-Pro-15:~ Carl$ ls -l /opt/local/lib | grep .so
-rwxr-xr-x 2 root admin 45152 Mar 11 12:19 libXcursor.1.dylib
-rw-r--r-- 2 root admin 50232 Mar 11 12:19 libXcursor.a
lrwxr-xr-x 1 root admin 18 Mar 11 12:19 libXcursor.dylib -> libXcursor.1.dylib
-rwxr-xr-x 2 root admin 1105 Mar 11 12:19 libXcursor.la
lrwxr-xr-x 1 root admin 32 Mar 11 21:19 libguile-srfi-srfi-1-v-3.so -> libguile-srfi-srfi-1-v-3.3.dylib
lrwxr-xr-x 1 root admin 36 Mar 11 21:19 libguile-srfi-srfi-13-14-v-3.so -> libguile-srfi-srfi-13-14-v-3.3.dylib
lrwxr-xr-x 1 root admin 32 Mar 11 21:20 libguile-srfi-srfi-4-v-3.so -> libguile-srfi-srfi-4-v-3.3.dylib
lrwxr-xr-x 1 root admin 33 Mar 11 21:20 libguile-srfi-srfi-60-v-2.so -> libguile-srfi-srfi-60-v-2.2.dylib
lrwxr-xr-x 1 root admin 17 Mar 11 21:21 libguile.so -> libguile.17.dylib
lrwxr-xr-x 1 root admin 30 Mar 11 21:22 libguilereadline-v-17.so -> libguilereadline-v-17.17.dylib
The easiest way to install Lilypond on macOS is to use lyp. Apart from installing lyp itself, which is a Ruby gem, there's no other dependency to install, no compilation step. Plus, you can install multiple versions of Lilypond and easily switch between them.
$ gem install lyp
$ lyp install lilypond
To install a specific version:
$ lyp install lilypond#2.19.53

Resources