The situation I face is that I seem to have two python3.6s on my MacBook Pro, one with the .dmg installer from the official python website, and one installed via Homebrew ( inferred by others, I don't remember whether it is right or not) :
TreaserdeMacBook-Pro:~ treasersmac$ python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
'['',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-
dynload', '/Users/treasersmac/Library/Python/3.6/lib/python/site-packages',
'/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages']
And this brings a result that even some packages have been successfully installed through pip3, they cannot be imported to python3 successfully, like:
TreaserdeMacBook-Pro:~ treasersmac$ pip3 install beautifulsoup4
Collecting beautifulsoup4
Downloading beautifulsoup4-4.6.0-py3-none-any.whl (86kB)
100% |████████████████████████████████| 92kB 4.3kB/s
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.6.0
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'bs4'
the same for the module Pillow, Installed Pillow but still get : ModuleNotFoundError: No module named 'PIL'
It is #hoefling that points out that I may have too many versions of python3.6.
Therefore, I think it reasonable to remove one of them.
Actually, I have no idea why there are two of them, and the time I began to learn and install python was about 2 years ago, so I cannot recall the details( that's why I use 'seem' at the beginning ), but one thing for sure is that I don't need two of them.
I use pycharm to code python. My operating system is macOS Sierra 10.12.6.
So the problems are:
which one of these python3.6s should I remove and how(which cmd to use)?
(Actually I don't quite understand how those packages work, like Pillow, how they link to python, can they serve for both version of python3.6, or can be directed to serve for a specific one, but how?.. And if I uninstall both of two versions and reinstall python3, can the packages I installed before work? )
other better solutions.
It's a problem that bugged me for a long time, I will appreciate it very much if someone can help me out.
Related
I'm still super new to coding! Trying to learn from online tutorials, but I seem to be stuck on the first step! I think I installed bs4, but it's not showing up in python3, is it installed in the wrong place?
robbie$ sudo -H pip install bs4
Requirement already satisfied: bs4 in /Library/Python/2.7/site-packages
Requirement already satisfied: beautifulsoup4 in /Library/Python/2.7/site-packages (from bs4)
Robbies-MBP:~ robbie$ python3
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[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>
ModuleNotFoundError: No module named 'bs4'
Any help would be greatly appreciated :)
Requirement already satisfied: bs4 in /Library/Python/2.7/site-packages
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
You have the module installed for Python 2.7, however you're using and trying to import it with Python 3.6.
You have to use pip3 like you use python3.
If you are using python 3 then you shoud use pip 3. In order to install it in ubuntu:
sudo apt install python3-pip
And then use the following command for installing the module bs4:
pip3 install bs4
go to the bottom left of your vs code and select python 3.9.1 64 bit (depending on the version of your python). it'll work.
it works for me
Just a quick note but a lot of times when this happens and you are running python3 and you used pip3 to install bs4 or another module but are running two different versions of python3 (eg 3.4 and 3.6). Sometimes just doing a normal update in a distro like CentOS installs a newer version of python, but not the corresponding pip.
Take for example here where a user is running python3.6 but all modules are installed only for python3.4 and there is no pip3.6 available.
http://realtechtalk.com/python_ModuleNotFoundError_No_module_named_bs4_even_though_you_have_the_module-2267-articles
I was having the same issue but managed to solve it with custom install script in the code. This tries to import and if it fails, automatically installs it
def safe_import(module):
try:
exec(f'import {module}')
globals()[module] = eval(module)
except ModuleNotFoundError as err:
import os
os.system(f'pip install {module}')
exec(f'import {module}')
globals()[module] = eval(module)
I am attempting to teach myself programming and keep running into problems downloading modules I need for basic tutorials.
My latest attempt has been to get the matplotlib module into my Python 3 environment. I have tried so many different install packages and so many advice I found on the internet that I cannot remember how I originally got the module. But it seemed that everything went well with the installation process.
I am using a Raspberry Pi2 throughout all of this with the Raspbian OS installed.
Python 3.2.3 (default, Mar 1 2013, 11:53:50)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib
ImportError: No module named matplotlib
It may be possible that you actually installed the library for python 2. I would use pip to install the modules that you need. If you don't already have it installed, run this first command in the shell:
sudo apt-get install python3-pip
This program can be called with "pip3" or maybe "pip-3.2" in the shell.
To install mathplotlib with it, try running:
pip3 install matplotlib
or
pip-3.2 install matplotlib
That should install the Python 3 module for you.
I use OSX 10.9 + Kivy 1.9.1, but I have two versions of Python, Mac OSX self-contained 2.7.5 and another standalone 2.7.9 installed. Here are the details:
MacBook-Air:wzy$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
MacBook-Air:wzy$ python
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.
After having installed twisted with pip install twisted, I get the following error message in kivy with python 2.7.5, which does not happen in python 2.7.9
MacBook-Air:wzy$ kivy
>>> import twisted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/twisted/__init__.py", line 53, in <module>
_checkRequirements()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/twisted/__init__.py", line 37, in _checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zope.interface.
MacBook-Air:wzy$ python
>>> import twisted
>>> exit()
I have even installed zope.interface several times and dedicate install target directory as one of the sys.path of kivy environment.
I do believe this is two version co-exist related, but how can I fix this?
When you do pip install twisted, you are installing Twisted into some Python environment, depending on which python executable you are invoking pip with. If you have a 2.7.5 environment and a 2.7.9 environment, pip install might be putting Twisted in a different place for each, depending on what other options you passed to pip. (You probably passed some other options to pip install because without privileges, by default, pip install will just fail. Did you do sudo pip install perhaps? Did you do pip install as an admin user into a homebrewed Python?)
The right way to do this is to only ever install Twisted into virtual environments. You can create a virtual environment with the -p option to virtualenv, which tells it which Python to use for that environment. Then, with the correct virtual environment active, you can pip install twisted and everything should work as you expect.
I had the same import error problem, providing another possible solution here:
I have zope.interface 4.4.2 installed, it turned out that my twisted version is too old. By upgrade twisted solved my problem.
pip install --upgrade twisted
Thanks Glyph,
Finally I find following simple command could directly fix this problem, because Kivy use his own virtualenv environment, but I do appreciated your kindly help.
kivy -m pip install twisted
Best Wish to you,
I am a bit of a noob on Mac and my python installation is refusing to acknowledge the existence of the rpy2 module on my mac. It looks like it only sees it as a Python 2.6 module. How do I make it visible in 2.7 ? Do I need to downgrade my python ? If so, how ? On the RPy2 web page (http://rpy.sourceforge.net/rpy2_download.html) Python 2.6 is recommended. Thanks!
mayumi#MAYUMI-iMac~:/ python --version
Python 2.7.6
mayumi#MAYUMI-iMac~:/ pip install rpy2
Requirement already satisfied (use --upgrade to upgrade): rpy2 in /Library/Python/2.6/site-packages/rpy2-2.3.8-py2.6-macosx-10.6-universal.egg
Cleaning up...
mayumi#MAYUMI-iMac~:/ python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpy2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named rpy2
>>>
I also found it is difficult to successfully install rpy2 in OSX machines. Sometime it works, sometimes it doesn't, which is very annoying. I eventually settled with Anaconda Python distribution from https://store.continuum.io/cshop/anaconda/ to save all the troubles. Installing rpy2 never fails since the switch.
The default installation of Anaconda does not included rpy2, so you want to run the installation command, from Anaconda folder, bin subfolder
conda install rpy2
Depends on the version, you may get a bunch of warnings. Just ignore them.
Then rpy2 just works! Of course, only under the Anaconda python, not the other python version you may have installed on your machine.
You can run a few test to make sure rpy2 works, following this example: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/3607712653c66d63e0d7f13f073bde8c0f209ba8/docs/examples/notebooks/rmagic_extension.ipynb
bash commands, run in the folder /Users/YOUR_USER_NAME/anaconda/bin/:
user-Mac-Pro:bin user$ conda install rpy2
and it says:
Conda package not available for rpy2, attempting to install via pip
Downloading/unpacking rpy2
Downloading rpy2-2.3.8.tar.gz (185kB): 185kB downloaded
Running setup.py egg_info for package rpy2
If you don't have R installed it will complain with a few warnings and fetch R for you. Then there may be some other depreciation warnings dependents on what you have installed.
(I am not associated with Continuum in any way)
You can see that pip installed to the site-packages to python 2.6 since you installed pip with python 2.6 it will default to use that library.
rpy2 in /Library/Python/**2.6**/site-packages/rpy2-2.3.8-py2.6-macosx-10.6-universal.egg
You can redirect pip installation location or use easy_install2.7 which should be around in /usr/local/bin/
I'll admit I'm completely dumbed by python install. Can someone help me on how to install module
I want to play with PyGame, PyOpenGL etc. So I install them, but I everytime I type "import pygame" error message shows up.
here's my environment so far.
In .bash_profile
PATH=${PATH}:/System/Library/Frameworks/Python.framework/Versions/Current/bin
Using easy_install PyOpenGL placed this
/Library/Python/2.5/site-packages/PyOpenGL-3.0.0b8-py2.5.egg
Locating pygame module
dchong:~ danielchong$ locate pygame
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/py2app/recipes/pygame.py
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/py2app/recipes/pygame.pyc
dchong:~ danielchong$ locate pyopengl
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/py2app/recipes/pyopengl.py
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/py2app/recipes/pyopengl.pyc
when I run python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygame
I'm not a huge fan of the default python install on OS X in the first place, mostly because it's usually a pretty old version. I find everything works better if I use the macports package.
easy_install seems to work better with the macports package, but maybe that's just because I'm too lazy to figure out all the nuances of the default install.
From what I can see there, it looks like the path to the packages isn't set correctly. Are you sure you're using the right site-packages directory?
See http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/