I installed django using pip install django==1.5.4 and I see it in the following directory:
/usr/local/lib/python2.7/site-packages/django
however, when I type in python and then say import django, I see the following output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
Is there anything else I can/need to do? I tried to uninstall and reinstall several times! I can confirm that 2.7.5 is the version of python used on my system...
EDIT
I realized now that if I type in python it defaults to Python 2.7.5. But if I type in python2 it defaults to 2.7.6.
They are installed in these locations:
/System/Library/Frameworks/Python.framework/Versions/2.7 -- 2.7.5
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7 -- 2.7.6
Is there anyway to make the 2.7.6 version the default when I type in python? Seems like django is installed there....
I figure that you have a link /usr/bin/python that points to your 2.7.5 version, so remove it and create other with the same name (python) to the version you want to use as default.
Nevertheless I recommends you to use virtualenvwrapper.
Related
I wanted to use turicreate library which doesn't support python 3.8 yet. So tried downgrading python to 3.7 using
downgrade python
But now I cant use pip. Even a simple command using pip like,
pip --version
gives me an error:
Traceback (most recent call last):
File "/usr/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
ModuleNotFoundError: No module named 'pkg_resources'
I have already tried downgrading pip to 19.0.3.
Also tried uninstalling and reinstalling both packages.
What can I possibly do? I use Arch Linux btw.
Instead of downgrading python for the whole OS, may be you should try using a downgraded python version for just your project.
Try using a virtual environment and use it to create a dev environment with python 3.7.
I am using macOS 10.13.1 (which is the latest version at this moment) on a MacBook Pro 13" Early 2015, and am trying to install the "quora" library for python 3.6.1. I am trying to install it by typing this into the terminal:
pip install quora
When I do so, it says it is already installed. Then when I type into the python IDLE IDE:
import quora
As a single line program, it says that no module named quora is found, yet when my terminal specifically says it has already been installed.
Any information about how I can fix this will greatly be appreciated. Thank-you.
Edit #1:
When I input in terminal:
pip3 install quora
And I run the import in IDLE, it gives this error message:
Traceback (most recent call last):
File "/Users/Hussein/Downloads/quora_install.py", line 1, in
import quora
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/quora/init.py", line 8, in
from user import User, Activity
ModuleNotFoundError: No module named 'user'
Edit #2:
Up until this point I have been using the IDE for Python 3.6. I tried to run the import in Python 2.7, which is the default for the Mac, and works fine. But I do not know if there are functions that I need that may have been added to Python after the 2.7 release. I still wish to continue trying to get it work for v3.6.1.
Do you have multiple Python versions on your machine? Try pip3 install quora?
I made a few experimentations upgrading from python 2.6.5 to python 2.7.11 in order to get Django to work properly. Then I had to uninstall python 2.7.11 and get back to python 2.6.5 (compatibility issues with other projects). Now, when I try to install django 1.2.1 using pip install django==1.2.1 I get this error:
C:\workspace\internal\trunk\ut_pr_01\src>pip install django==1.2.1
Downloading/unpacking django==1.2.1 Running setup.py egg_info for
package django
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\maxim\appdata\local\temp\pip-build\django\setup.py", line
32, in <module>
version = __import__('django').get_version()
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\__init__.py",
line 3, in <module>
from django.utils.version import get_version
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\version.py",
line 7, in <module>
from django.utils.lru_cache import lru_cache
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\lru_cache.py",
line 28
fasttypes = {int, str, frozenset, type(None)},
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\maxim\appdata\local\temp\pip-build\django\setup.py",
line 32, in <module>
version = __import__('django').get_version()
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\__init__.py",
line 3, in <module>
from django.utils.version import get_version
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\version.py",
line 7, in <module>
from django.utils.lru_cache import lru_cache
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\lru_cache.py",
line 28
fasttypes = {int, str, frozenset, type(None)},
^
SyntaxError: invalid syntax
---------------------------------------- Command python setup.py egg_info failed with error code 1 in
c:\users\maxim\appdata\local\temp\pip-build\django Storing complete
log in C:\Users\Maxim\pip\pip.log
It seems like the version of python is what causing the problem but previously I installed any django with same pip and same python versions.
My environment currently:
pip 1.2.1,
python 2.6.5,
windows 10 64bit, needed django version: 1.2.1
Anyone with an idea?
You can have multiple version of Python installed on Windows (what you seem to be using) without any problems. You just have to make sure the default version of Python is set correctly for your situation.
Instead of using an extremely outdated version of django, install the latest version of Python - just choose a different path for it from the installer. So instead of C:\Python27 set it to C:\Python-27 or anything else.
If you are installing Python 3, you don't have to change the path since Python 3 installs itself in C:\Program Files (the default location for programs in Windows) and thus will not clash with Python 2 which installs directly onto the C:\ drive.
Once you have an updated version of Python installed, you just have to make sure that you call that version of Python when you need to install django. To do this effectively, use a Python virtual environment.
Lets assume you have installed the latest version of Python 2 in C:\Python-27, here is how you would install the latest version of django against it:
First, you need to install the virtualenv package. Open a command prompt and then type the following (the > is the prompt, don't type that):
> C:\Python-27\Scripts\pip.exe install virtualenv
A few minutes later you should have virtualenv installed, next step is to install django inside a new virtual environment:
> C:\Python-27\Scripts\virtualenv.exe C:\%USER%\Desktop\django-env
Once that is done, you need to activate the environment, and install django:
> C:\%USER%\Desktop\django-env\bin\activate.bat
(django-env) > pip install django
Now you have the latest version of django installed on an updated version of Python.
Managing these environments can be difficult; so I would suggest downloading a Python IDE. PyCharm is what I use and there is a free community version available. It will make it easy to manage all the different versions of Python for you.
Python 2.6 does not have set literals.
# in python 2.6 only this will work
fasttypes = set(int, str, frozenset, type(None))
# in python 2.7+ this will work as well
fasttypes = {int, str, frozenset, type(None)}
The version of Django you are using is not compatible with python 2.6.5
Support for Python 2.6 was dropped in Django 1.7, so I'm not sure why you get this error when you try to install Django 1.2.1. Maybe a more recent version is residing in the temp\pip-build\ directory. Since it's called temp it should be safe to delete that directory.
In any case, Python 2.6 and the corresponding Django versions are insecure and unsupported. I highly recommend using a current version instead. If other projects need old deprecated Python versions, you should use virtual environments to isolate them.
The problem was solved by installing the Django version I need - 1.2.1 not using pip but downloading the files and manually running:
python setup.py install .
My sublime REPL is currently running python 2.6.1, I have no idea how seeing as I have never downloaded it. I am trying to install matplotlib and keep getting this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
So I thought installing python 2.7.5 would make this work instead, how do I do this?
When you hit Ctrl` to go to the console, you are using the internal version of Python that comes included with Sublime Text 2. You cannot run external modules with this version, it is static.
If you want to use your system Python, install Package Control, then install SublimeREPL. By default, this will use the version of Python that comes first on your system's PATH. Once running, as long as you've properly installed matplotlib, you should be able to import and use it within SublimeREPL with no problems.
Here is a post about installing a module in python3. When I use brew install python, then it installs it for 2.7.
When I use the method suggested by dan, which aimed to install it directly in python3 (who i really thank), but which didn't work :
# Figure out the path to python3
PY3DIR=`dirname $(which python3)`
# And /then/ install with brew. That will have it use python3 to get its path
PATH=$PY3DIR:$PATH brew install mapnik
The installation was successful but in python2. so I get:
For non-homebrew Python, you need to amend your PYTHONPATH like so: export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
so i finally add the path manually in python3 :
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
I get this error :
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/mapnik/__init__.py", line 69, in <module>
from _mapnik import * ImportError: dlopen(./_mapnik.so, 2): Symbol not found: _PyClass_Type Referenced from: ./_mapnik.so
Expected in: flat namespace in ./_mapnik.so
Please help, I have spent so many hours on this ...
Thanks!!!
The Mapnik python bindings depend on boost_python. And both need to use the same python. The problem is likely that homebrew is providing a bottle of boost which includes boost python built against python 2.7 and not python 3.x.