Mac OSX: Error after installing Django - No module named django - python

I am using MacOS X 10.7.5 and am a TOTAL newb at Python
I am pretty sure django installed correctly as per https://code.djangoproject.com/wiki/Distributions
$ sudo port install py27-django
---> Computing dependencies for py27-django
---> Cleaning py27-django
---> Scanning binaries for linking errors: 100.0%
---> No broken files found.
$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[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 django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django

The issue was with that a prior Python was installed (2.7.1) previously and MacPorts installed a new one (2.7.6) but did not update the Mac Sym links etc
So I had to futz with my PATH
$ vi ~/.bash_profile
.
.
export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
.
.
$ source ~/.bash_profile
$ python --version
Python 2.7.6
$ python
Python 2.7.6 (default, Nov 12 2013, 13:12:10)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print django.get_version()
1.5.1

Related

Running “import tensorflow” on Mac generates "No module named tensorflow" error

Actually I already installed tensorflow by using
$ pip install tensorflow
and it works well when I use
$ python
Python 2.7.15 (default, Jul 23 2018, 21:27:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import tensorflow
>>>
but when I use python3 on command line
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>>
it shows an error, and it shows the same error when I use IDLE
use
pip3 install tensorflow
pip installs to default python directory. pip3 installs to python3

Can't Import Django using Python3 on macOS Sierra

Have both versions of Python (Legacy 2.7.10 and 3.6.2) installed on macOS Sierra.
Installed pip using the following steps.
Downloaded it using curl:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Installed pip it by running the installer script:
sudo python get-pip.py
Checked for any upgrades / updates for pip:
sudo pip install -U pip
Installed django 1.11:
sudo pip install django==1.11
When I run python (legacy):
python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
1.11
However, when trying it using python3:
python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
Note: I followed a different tutorial and got python3 working with django 1.11 using virtualenv - please don't suggest this as I am new to the python world and just want to use python3 / django 1.11 in a non-virtual environment - I just want have it working like the legacy python interpreter is behaving.
pip installs libraries differently for python2 and python3, so you effectively have different environments for each. If you want to install Django for python3, you'll want to install it like this:
pip3 install django==1.11

OSX Change Default Interpreter Python (importing matplotlib)

I try to visualize graph with matplotlib in python but I have few problem in my mac (Yosemite 10.10.2). I already installed matplotlib, and I know that I have 2 version of python installed in my computer, which are 2.7.8 and 2.7.6
Using default interpreter which is python 2.7.8, I got this error
dhcPlus-mbp:~ macbook$ python
Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
But if I try this one, it works on terminal. But I can't build straight from my Sublime with Ctrl+B
dhcPlus-mbp:~ macbook$ /usr/bin/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 matplotlib
>>>
My question is, how could I change default python interpreter so I can use the 2.7.6 in my environment?
Any help is greatly appreciated. Thank you very much.
This problem solved by removing the extra Python libraries on Mavericks by
sudo rm -rf /Library/Frameworks/Python.framework/

Python version confusion + cairo

I have python installed in two locations, in os default it's 2.6.6 and in /usr/local/bin/python2.7 has 2.7.
I have installed cairo (cairo-1.12.18) via source using configure/make/make install, but it appears to have installed under python 2.6.6. How do I install it for python2.7?
[root#xxxxx ~]# python
Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
>>>
[root#xxxxx ~]# /usr/local/bin/python2.7
Python 2.7.8 (default, Nov 18 2014, 11:15:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cairo
>>>
Thank you.
Be sure to install it using python 2.7 and not python 2.6 (run make and make install using python 2.7). I assume you use Linux OS so your default Python is 2.7, you can change your default Python but it's not recommended due to several reasons. Please look at this StackOverflow question and answers for more informations:
Two versions of python on linux. how to make 2.7 the default

Python, Ubuntu: Install PyPi package for a specific Python version

I've installed Python 3.3 alongside Python 2.75 on my Ubuntu machine. The problem is that easy_install gets packages for the default, 2.75 version only, e.g:
easy_install pymongo
$ python
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>>
But:
$ python3.3
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pymongo'
How can I install PyPi packages for the Python 3.3 installation?
You need easy_install3. In apt-get you get it by
apt-get install python3-setuptools

Categories