django virtualenv mimeparse import error - python

I can't for the life of me figure out what I'm doing wrong, here's what's going on:
I'm running google appengine with django on my local dev
this is happening from within a virtualenv running python2.5
I have installed the mimeparse package using pip install -E for that virtualenv
I have verified this by checking the site packages in my 'something-env/lib/python2.5/site-packages' for the mimeparse.py
running the python shell lets me import mimeparse
running python manage.py shell also lets me import mimeparse
running python manage.py runserver will fail on import mimeparse, but in the pretty django error page I can see that the python path contains the something-env/lib/python2.5/site-packages folder
what can I be doing wrong?
NOTE: copying the mimeparse.py into the project root will work, but that is not exactly pretty.

If you get stuck running Ubuntu, with the following import error: no module named mimeparse, just install it, by adding the following line on your terminal in the appropriate directory :
pip install mimeparse
There is a debian package:
sudo apt-get install python-mimeparse
But, I didn't need to install the debian package. Just the first command and works for me.
Don't forget to activate your env.
source $PYTHON_HOME/activate
My $PYTHON_HOME points to my virtualenv python.

Related

Is there a way to install Flask globally

I am new to Python. Today I installed flask in C:Users\myName\FolderA using below commands and it worked fine. But when i try to create a structure C:Users\myName\FolderA\FolderB and create app.py in it, my VSCode says "ModuleNotFoundError: No module named 'flask'". Does this mean i need to install flask in Folder B too? Is there a way to install flask globally and make all folders under 'FolderA' access the libs?
Commands used to install Flask
C:Users\myName\FolderA\py -m venv env
C:Users\myName\FolderA\env\Scripts\activate
(env)c:Users\myName\FolderA\pip install flask
You are using a virtualenv. Everything installed inside a virtualenv resides inside that virtualenv (which is nice in fact: all your dependencies for that project only!).
If you want to install packages globally, run
pip install flask
without having run the activate script first (that activates your virtualenv).
PIP should install packages globally. You shouldn't have to reinstall flask everytime. Seems like something is wrong with your PIP. How did you install Python?
You could try updating PIP, which could fix it. Try running
python -m pip install –upgrade pip
in cmd.
Edit: This could also be an issue with Visual Studio Code. Try running the python code through CMD.

Python (Windows Server) Virtualenv not recognizing Django is installed

My virtual environment refuses to recognize my install of Django (strangely)
I'm on Windows Server, installed Python 3.7 to a directory (C:\Python37) which I have C:\Python37;C:\Python37\Scripts in my windows Path so when using Powershell or GitBash I can use the python command.
if I run where python it shows the default install
I CD into my django project directory and run:
python virtualenv venv and the venv directory is created
Then I run source venv/Scripts/activate and it activates appropriately.
When I run where python it shows the exe inside the venv directory - which is expected and appropriate.
I run pip install -r requirements.txt and all my requirements install appropriately. I confirm they are installed with pip freeze (all installed correctly)
Once I do that I go to run python manage.py collectstatic (no migrations are required in this particular instance) I get an error message that Django isn't installed.
To check this, with my virtualenv still activated I enter the shell (python)
If I do import django it also says Django is not installed.
I cannot figure out what's happening here - the python version appears to be correct, the correct virtualenv is activated - but it's still not seeing the properly installed Django installation.
Thoughts? Ideas?
For what it's worth - here is the solution and explanation:
Everything works as expected as was outlined in the question - the reason that the actual python command wasn't working had to do with a line in the .bashrc file.
There was an alias in the .bashrc file to set python to the command winpty C:\Python37\python
So when the command python manage.py collectstatic was getting ran - it was looking at the Python executable in the Python37 directory and not the virtualenvironment Python.
This was solved by simply running the appropriate Python (e.g.)
C:/my_project/venv/Scripts/python manage.py collectstatic
This forced it to use the virtualenvironment python to run the command so everything worked as expected.

install django in virtualenv python3.4 with linux os in virtualenv

I am getting this error when importing django inside python :
ImportError: No module named 'django'
I've got a problem when installing django in my web server aws, I made an alias python = python3
so when I am working with python it is python 3.4 which is executing.
I made a virtual env with it, but when I install django even inside the virtual env, it is installing in the python 2.7 version, not in my virtualenv, and not with the python3 version.
does anyone knows how to make really my python3 as default or how I can install django in the correct folder (python3)
When you create a virtualenv, you need to show that you want to use python3. Do the following:
$ which python3
/usr/local/bin/python3
$ mkvirtualenv name --python=/usr/local/bin/python3
then try to install django:
$ pip install django
Hope it helps

No module named django.core when running django-admin startproject myproject

when running django-admin startproject myproject on macOS I get the error
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 2, in
from django.core import management
ImportError: No module named django.core
I checked out this question but running import django won't produce any output in a python3 shell.
/usr/local/bin/django-admin is a symlink to /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/bin/django-admin.py.
I already put /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django in my PYTHONPATH as suggested in other questions.
Am I missing something?
Even if you make it work, it is not good practice to do what you're doing! Ideally, the only python-related binaries you would want in /usr/local/bin/ would be python, pip and virtualenv (or venv, pyvenv)...
I would suggest you to delete /Library/Frameworks/Python.framework/Versions/3.6 ONLY IF you installed it there. As far as I know, macOS only comes with python2.7 installed and not python3.6!
Then open a new shell and try this:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install python3
pip3 install virtualenv
cd ~/Desktop/
mkdir proj
cd proj
virtualenv -p python3 env
source env/bin/activate
pip install django
django-admin.py startproject testproj
skip the first step if you already have brew installed
Check your permissions in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ with an ls -la command. If you see anything owned by root, this probably needs to change. I suspect that since you installed some packages as root, the permissions are weird and it can't find the module. If this is the case, reinstall the package(s) as your own user using sudo.
Another thing you should check: as phd mentioned you need to make sure you're using the version of python you think you are. Check this by running which python to tell you the location of the one you're referencing, and python --version to tell you which version you're using. If it's not Python 3.6, then you installed Django for a different version of Python. In this case, simply install Django for version 3.6 and you'll be on your way.
For future reference, Python offers a module called venv to prevent version mishaps like this. More info can be found here.
It seems like you are trying to create or work on a django project without using a python virtual environment. I recommend reviewing the python 3 venv documenation (https://docs.python.org/3/library/venv.html). Then creating a virtual environment (venv) specifically for your web application. Once you you that project's venv setup you can install django into that venv.
On MacOS, use sudo before the command:
sudo django-admin startproject myproject

No module named changelist_ordering

I am trying to import changelist_ordering. So I have tried to install the package django-changelist-ordering. But I am getting the error:
No matching distribution found for changelist-ordering
Can anyone help me to solve this issues.
First of all install changelist-ordering by performing the following steps:
git clone https://github.com/SergeyKubrak/django-changelist-ordering
cd django-changelist-ordering
sudo python setup.py build
sudo python setup.py install
or you can install the package by running just one command (#jonrsharpe):
pip install git+https://github.com/SergeyKubrak/django-changelist-ordering
Now in your projects settings, include the app changelist_ordering in your INSTALLED_APPS
and then wherever you wanna use ChangeListOrdering import as
from changelist_ordering.admin import ChangeListOrdering
If this also does not work for you, check whether the module is installed in your virtual environment or not with
pip list | grep changelist-ordering
This should get you a result if changelist-ordering is present in your virtual environment else your Django application is trying to access the module which is not present in your virtual environment.

Categories