Mac OSX Upgrade now Django Not Found [closed] - django

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have been using an outdated Mac operating system (10.5.8), but recently updated to 10.8. However, now django isn't being found anymore.
Operations such as:
python manage.py runserver
that worked before now return:
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
I read another post here where the user suggested checking if django was available using python -c 'import django'. Django is not available using that command, and I tried to modify my PYTHONPATH to point to where the django package was (in my Downloads folder), but that didn't work either.
Anyways, I'm confused as to why it worked before but not now? Maybe because this version of OSX uses a different version of Python?
PS I am not using a virtualenv. Thanks for any ideas!

I think when you upgraded to Mac OS X 10.8 your site-packages/ libraries were removed and now it sounds like you just need to install django again. Make pip install django.
Besides usage of virtualenv is a good practice to follow. In that particular case your virtualenv contained all necessary packages and you just had to install virtualenv instead of a bunch of libraries.

When you upgraded OSX, you almost certainly got a new default version of Python. 10.5 had Python 2.5, but 10.8 has 2.7. Libraries are installed for a specific version, so you'll just need to reinstall with the new version.

Related

Django projects fail on Ubuntu 20.04 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I just upgraded Ubuntu from 18.04 to 20.04, and ALL my Django projects (tens of them) were not working.
One of the problem related to psycopg2 when executing pip:
For example, there is "psycopg2==2.7.3.1" in my "requirements.txt" file, and running "pip install -r requirements.txt" resulted in errors when building wheel for psycopg2.
Change "psycopg2==2.7.3.1" to ""psycopg2-binary" solved the problem.
So, is such change necessary for all projects running on Ubuntu 20.04?
Other error examples from various projects when running server:
RuntimeError: __class__ not set defining 'AbstractBaseUser' as <class 'django.contrib.auth.base_user.AbstractBaseUser'>. Was __classcell__ propagated to type.__new__?
SyntaxError: Generator expression must be parenthesized (widgets.py, line 151)
AssertionError: SRE module mismatch
ModuleNotFoundError: No module named 'decimal'
... etc.
How to I fix these problems? I've been in a headache for weeks.
Your problem with psycopg2 is apparently due to an incompatibility between python 3.8 and older versions of psycopg2. (Issue #854)
The problem has been fixed, but it was not backported to the release that you are using. It has however been backported to the binary psycopg2 releases in various Linux distros.
So ... yes ... you are going to have to make some changes for all of your Django projects that use psycopg2 to get them to run on vanilla Ubuntu 20.04.
However, it looks like there are at least 3 ways to "fix" this:
Change to the "binary" package as you have done.
Change the psycopg2 version in your "requirements.txt" to 2.8.6 or later1.
Build, install and use python 3.7 or earlier. (Probably a bad idea in this case.)
1 - Or maybe 2.8.0_BETA2 or later because it looks like the fix has been backported that far in the source code repo. It depends on whether the patched releases were uploaded to PyPi ... which I didn't check. But all things being equal, updating to the most recent compatible version is preferable.

Anaconda error after install on Windows

I want to install Anaconda on my x64 Windows machine, and I downloaded the Python 2.7 version 64-bit installer. The installation process looks good.
Then I installed pip with choco and installed several packages like zbar,
however, when I want to try to launch Anaconda, I entered conda in Powershell, this is what I got:
Traceback (most recent call last):
File "C:\Users\Ruiyang\Anaconda2\Scripts\conda-script.py", line 3, in <module>
import conda.cli
ImportError: No module named conda.cli
Does anyone knows how to fix this?
add anaconda's bin directory to path.
set path=whatever\anaconda\bin;path;
This issue is related to the path variable setting. Quoting from another SO post:
fire up your interpreter and add this line: export PATH=/Users/add
your username here/anaconda/bin:$PATH
Now type python into the interpreter and you will see Anaconda 1.8.0
or whatever version you have. You will have to do this each time you
start a new interpreter.
Also, note that this might occur when the user name in the path on windows contains a space character. Taken from here.
Though #devautor's method doesn't work for me, a comment in his reference shows me the correct answer:
Unset both PYTHONPATH and PYTHONHOME, then my problem is solved.

cannot use ortools from Google

I installed or tools onto a macbook pro running Mavericks (10.9.5) as per these directions
I did initially get the error described here: can't install or-tools on mac 10.10
and followed the recommendation using easy_install. yes I did get the error they describe but it seemed that or tools installed properly. Issuing
import ortools
at the python prompt did not generate an error.
Then I went to try one of the examples google provided (see first link above) and get this error:
Traceback (most recent call last):
File "examples/golomb8.py", line 26, in <module>
from google.apputils import app
ImportError: No module named google.apputils
Obviously I missed something. Can someone enlighten me??
Your issue here is that the google.apputils module is separate from ortools and needs to be installed separately. You can check ortools is installed by running some other examples in the Google provided repo such as python examples/map.py , or the example in this repo and ensuring python optimize.py results in the expected NBA lineup (such was my original reason for looking into ortools :-)).

Spatialite with Python 2 and 3

I am attempting to use spatialite with both Python 2 and 3 on Windows 7.
Rather than try to patch pyspatialite for Python 3, I decided to use the load_extension approach with sqlite3 Python built-in package, similar to how is done here: Sqlite load_extension fail for spatialite in Python and here: Use spatialite extension for SQLite on Windows.
But, on the official (C)Python 2.7 installer, the load_extension was disabled for an issue related to MacOS. This is not with the counterpart for Python 3.4. Furthermore, both installers are built without SQLITE_ENABLE_RTREE=1 (that I'd also like to have).
At first, for Python 2.7, a workaround was to build pysqlite tweaking the setup files to have both R*Tree and extensions. This way does not work for Python 3, since it does not seem to be supported by the current setup.py. From my understand, this is because the package moved to the core Python repository: https://github.com/ghaering/pysqlite/issues/72#issuecomment-94319589
My current solution was to re-build both Python 2.7 and 3.4 with required settings for sqlite3 package. It worked, and I was able to load spatialite as an extension and to create R*Tree.
Does it exist an alternative simpler solution? Did somebody find an alternative solution by working on the setup.py of pyspatialite or pysqlite?
There is an easier solution that I just got working. I'm running Windows 10 with Python 3.5 using the default sqlite3 package, and Spatialite 4.3.
This is how I did it:
Let start with a simple program that loads the spatialite extension (which we haven't installed yet):
import sqlite3
with sqlite3.connect(":memory:") as conn:
conn.enable_load_extension(True)
conn.load_extension("mod_spatialite")
If you run this program you get:
C:\> python test.py
Traceback (most recent call last):
File "test2.py", line 5, in <module>
conn.load_extension("mod_spatialite")
sqlite3.OperationalError: The specified module could not be found.
That means it can't find the mod_spatialite extension. Let's download it from the Spatialite website. At the bottom there's links to "MS Windows binaries". I picked the x86 version, current stable version, and downloaded the file called mod_spatialite-4.3.0a-win-x86.7z. Unzipping that file to the same directory your test.py file is in, and running the program now produces no errors (ie. it works!):
C:\> python test.py
C:\>

Could not find platform independent libraries <prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]

I'm really new to Python and Django.... What I'm trying to do is:
Install Python 2.7 on Mac OS 10.6.8
Install pip Install Django
Install virtualenvwrapper
Create virtual environment
Install Django-Cms
I think, I'll be is ok from Install virtualenvwrapper to the Django-Cms installation because I have already done it, but in the first steps I got some troubles.
I download Python 2.z from python.org the Python 2.7.3 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6 and later [2]), installed whit the wizard . That create a directory /System/Library/Frameworks/Python.framework/Versions with inside my 2.7 folder.
My directory /System/Library/Python is empty
I'm sure I've Python installed cos:
python --version
Python 2.7.3
but when I try easy_install pip it gave me:
Could not find platform independent libraries <prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback
Traceback (most recent call last):
File "/usr/bin/easy_install-2.6", line 7, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 16, in <module>
import sys, os, zipimport, time, re, imp, new
ImportError: No module named os**
Now no idea of what does mean ...so if somebody could help out from this and put me on the direction where I can istall my virtualenvwrapper I can take it from there.
I'm Junior a front end developer never touch back end so pls be specific and explain me what I need to do as u speak with a child.
You seem to have things turned around. Virtualenv creates a python environment that encapsulates a python install. So you want to do the following:
Install python
Create a virtualenv using that version of python (eg. virtualenv --python="path to python in 1" virt)
Switch to that virtualenv (workon virt)
Now install Django, etc. inside of the virtualenv virt
Here is the recipe I used to get my environment setup and running.
Are you using homebrew? I've found that's the most reliable way to get stuff on the mac.