Uninstall Django completely - python

I uninstalled django on my machine using pip uninstall Django. It says successfully uninstalled whereas when I see django version in python shell, it still gives the older version I installed.
To remove it from python path, I deleted the django folder under /usr/local/lib/python-2.7/dist-packages/.
However sudo pip search Django | more /^Django command still shows Django installed version. How do i completely remove it ?

pip search command does not show installed packages, but search packages in pypi.
Use pip freeze command and grep to see installed packages:
pip freeze | grep Django

Got it solved. I missed to delete the egg_info files of all previous Django versions. Removed them from /usr/local/lib/python2.7/dist-packages. Also from /usr/lib/python2.7/dist-packages (if any present here)
sudo pip freeze| grep Django
sudo pip show -f Django
sudo pip search Django | more +/^Django
All above commands should not show Django version to verify clean uninstallation.

Use Python shell to find out the path of Django:
>>> import django
>>> django
<module 'django' from '/usr/local/lib/python2.7/dist-packages/django/__init__.pyc'>
Then remove it manually:
sudo rm -rf /usr/local/lib/python2.7/dist-packages/django/

open the CMD and use this command :
**
pip uninstall django
**
it will easy uninstalled .

first use the command
pip uninstall django
then go to python/site-packages and from there delete the folders for django and its site packages, then install django. This worked for me.

Remove any old versions of Django
If you are upgrading your installation of Django from a previous version, you will need to uninstall the old Django version before installing the new version.
If you installed Django using pip or easy_install previously, installing with pip or easy_install again will automatically take care of the old version, so you don’t need to do it yourself.
If you previously installed Django using python setup.py install, uninstalling is as simple as deleting the django directory from your Python site-packages. To find the directory you need to remove, you can run the following at your shell prompt (not the interactive Python prompt):
$ python -c "import django; print(django.path)"

I had to use pip3 instead of pip in order to get the right versions for the right version of python (python 3.4 instead of python 2.x)
Check what you got install at:
/usr/local/lib/python3.4/dist-packages
Also, when you run python, you might have to write python3.4 instead of python in order to use the right version of python.

On Windows, I had this issue with static files cropping up under pydev/eclipse with python 2.7, due to an instance of django (1.8.7) that had been installed under cygwin. This caused a conflict between windows style paths and cygwin style paths. So, unfindable static files despite all the above fixes. I removed the extra distribution (so that all packages were installed by pip under windows) and this fixed the issue.

I used the same method mentioned by #S-T after the pip uninstall command. And even after that the I got the message that Django was already installed. So i deleted the 'Django-1.7.6.egg-info' folder from '/usr/lib/python2.7/dist-packages' and then it worked for me.

The Issue is with pip --version or python --version.
try solving issue with pip2.7 uninstall Django command
If you are not able to uninstall using the above command then for sure your pip2.7 version is not installed so you can follow the below steps:
1)which pip2.7
it should give you an output like this :
/usr/local/bin/pip2.7
2) If you have not got this output please install pip using following commands
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python2.7 get-pip.py
3) Now check your pip version : which pip2.7 Now you will get
/usr/local/bin/pip2.7 as output
4) uninstall Django using pip2.7 uninstall Django command.
Problem can also be related to Python version.
I had a similar problem, this is how I uninstalled Django.
Issue occurred because I had multiple python installed in my virtual environment.
$ ls
activate activate_this.py easy_install-3.4 pip2.7 python python3 wheel
activate.csh easy_install pip pip3 python2 python3.4
activate.fish easy_install-2.7 pip2 pip3.4 python2.7 python-config
Now when I tried to un-install using pip uninstall Django Django got uninstalled from python 2.7 but not from python 3.4 so I followed the following steps to resolve the issue :
1)alias python=/usr/bin/python3
2) Now check your python version using python -V command
3) If you have switched to your required python version now you can simply uninstall Django using pip3 uninstall Django command
Hope this answer helps.

If installed Django using python setup.py install
python -c "import sys; sys.path = sys.path[1:]; import django; print(django.__path__)"
find the directory you need to remove, delete it

Related

pip/python: normal site-packages is not writeable

I have a new Macbook - a user installed it, and then I installed a new user (mine), granted admin privileges and deleted the old one. I am on OS Catalina.
Since the installation I've been having several permission problems.
VSCode can't find Jupyter Notebook, pip installs packages at ~/Library/Python/3.7/site-packages.
When I do which python3 I get usr/bin/python3.
When I do pip3 install <package> I get: Defaulting to user installation because normal site-packages is not writeable And then it says it has already been installed, even though I can't access it when I do import <package>.
It's seems clear that this is a permission problem, pip can't install to the "base" python, and them python can't find what I've installed into ~/Library/Python/3.7/site-packages.
I've tried reinstalling the OS, but since I haven't done a clean install, it didn't change anything.
What am I missing?
How exactly can I fix permissions? Where do I want packages to be installed (venv sure, but some packages I want global (like jupyter).
As #TomdeGeus mentioned in the comments, this command works for me:
Python 3:
python3 -m pip install [package_name]
Python 2:
python -m pip install [package_name]
It's best to not use the system-provided Python directly. Leave that one alone since the OS can change it in undesired ways, as you experienced.
The best practice is to configure your own Python version(s) and manage them on a per-project basis using virtualenv (for Python 2) or venv, possibly via poetry, (for Python 3). This eliminates all dependency on the system-provided Python version, and also isolates each project from other projects on the machine.
Each project can have a different Python point version if needed, and gets its own site_packages directory so pip-installed libraries can also have different versions by project. This approach is a major problem-avoider.
python3.7 -m pip install [package_name]
(you should use the version that you have, of course)
solved it for me.
The most voted answer python3 -m pip install [package_name] does not help me here.
In my case, this was caused by a conflict with the dominating 3.6 version that was also installed as a default. You might ask yourself why you have 3.6 on your system, you will most probably not use that version now. The reason is that 3.6 is used as an independent default python version for many package installers. Those installers do not want to check which individual version you use and whether that fits, they just use 3.6 as a default, if you like it or not.
Here is a proof by example --upgrade pip:
pip3 install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in
/home/USERNAME/.local/lib/python3.6/site-packages (20.3.1)
python3 -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in
/home/USERNAME/.local/lib/python3.6/site-packages (20.3.1)
python3.7 -m pip install --upgrade pip
Collecting pip
Cache entry deserialization failed, entry ignored
Using cached https://files.pythonhosted.org/packages/ab/11/2dc62c5263d9eb322f2f028f7b56cd9d096bb8988fcf82d65fa2e4057afe/pip-20.3.1-py2.py3-none-any.whl
Installing collected packages: pip Successfully installed pip-20.3.1
I'm using Anaconda on Ubuntu and had the same problem.I fixed it by the following steps:
deactivating current environment
conda deactivate
Then, the base environment activates. I deactivated the base conda environment too. To do so, I used conda deactivate again.
Finally, I activate my project environment directly (instead of activating from the base environment) by the following command. Afterward, I installed the intended package successfully and worked perfectly.
conda activate myenv
pip install somepackage
sudo pip install
Worked for me. But pip install is not recommended to be run with sudo. The issue I was facing on BIGSUR was, it was using system python. Once I Installed python 3.9 using
brew install python#3.9
Then pip worked fine
For readers who thought themselves accidentally update system pip:
If you saw this info in your terminal output:
Defaulting to user installation because normal site-packages is not writeable
then you will be fine. Use the pip3 you just updated to run:
pyenv global system # since I use pyenv
pip3 uninstall pip # this one does the trick
Then you can check again pip3 --version will point to the original old (XCode/System-)pip. E.g. (2022/2/28):
pip 20.2.3 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
It occurs with me when I the virtual enviroment folder name was : venv.
in this case, It gives errors like :
No module pip
Default folder is unwritable
renaming the folder solve the proplem.
Check on the command line "which python" to see if it is the value you expect.
If you have a virtual environment activated, check /venv/bin/activate to see the value of VIRTUAL_ENV= and make sure it is the correct path . The path may be wrong if you renamed or moved the project. If the path is wrong, you can delete the venv and make a new one.
For me, none of the suggestions worked so I had to delete the current virtual environment folder venv and recreate it using one of the following commands:
python -m venv venv
python3 -m venv venv
Check the source of pip on Ubuntu 20.04
which pip
returns the correct path
/home/myname/fullstack/person_api/venv/bin/pip
UPDATE
I presume that some might encounter this problem because they set python path as environmental variable like this in ~/.bashrc:
python=/path/to/python
which you should not be doing! Instead we could do:
py=python
PATH=/path/to/python:$PATH
I bumped into this issue specifically because of this!
Had this same issue on a fresh install of Debian 9.12.
Rebooting my server solved the issue.
In my case on Linux, the ownership of the conda env directory had changed to another Linux user (long story), and so the the normal site-packages was not writeable due to a permissions issue.
The solution was to change ownership back to the user doing pip install.
I met exactly the same issue.
I just type sudo python3.8 -m pip install .... and the error disappeared.
If I remove the sudo, issue remains.
For those running on a Pi, that accidentally installed pip as root. Just chown the lib folder to the pi user:
sudo chown -R pi:pi /usr/local/lib/python3.9/
in my case python3 -m pip install [package_name] did not solve that.
in my case, it was a problem related to other processes occupying the directory.
I restart Pycharm and close any other program that might occupy this folder, and reinstalled the package in site-packages directory successfully.
When this problem occurred to me I have tried all the mentioned approaches but they don't seem to work.
Instead, restarting Python language server in my VSCode did the job - my SimPy package is now found. On Mac it is Cmd+Shift+P and select "Python: Restart Language Server".
Had similar issue on Ubuntu 20.04.4 LTS in VirtualBox, but none of the suggestions here worked for me.
I was trying to install open3d in a venv and every time I was getting
"Defaulting to user installation because normal site-packages is not writeable"
which at first I didn't even noticed. open3d was always being installed in /usr/bin/python3 environment. I've restarted the VM but without luck, so I guess the problem was not just missing write access.
So in VS Code, which was using the venv, importing open3d was not possible. But testing from terminal from the activated venv with python3 -c "import open3d as o3d; print(o3d.__version__)" was working fine and that confused me totally. I even broke my system pip installation using sudo, see further below if you want to know how to fix it.
Anyhow, the solution to my problem was to explicitly point to the python3 file in the venv where I wanted to install the package:
venv/bin/python3 -m pip install open3d
So I was testing out everything and eventually installed with sudo: sudo pip3 install open3d. This of course didn't solved the problem and open3d was still missing in the venv. Even worse, I got the message:
"WARNING: You are using pip version 21.3.1; however, version 22.0.4 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command."
So I did it but with sudo, updating the system pip and then found out here that this is not good:
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Following an advice here, I tried to revert to original version, only then pip3 broke:
sudo pip3 uninstall pip
sudo pip3 --version
sudo: pip3: command not found
The apt package was still there:
sudo apt install python3-pip python3-pip is already the newest version
(20.0.2-5ubuntu1.6).
So I had to reinstalled to fix the problem:
sudo apt-get remove python3-pip
sudo apt install python3-pip
Maybe you have python, python3, pip or pip3 aliased. In that case pip might not work well anymore, as the alias isn't always available and so pip/pip3 might resolve python/python3 differently compared to in your terminal.
That could give rise to pip/pip3 trying to install in the system python, and that could give rise to your error.
I tried ever single recommendation described here. In every instance, I get the exact same result: SyntaxError: invalid syntax (<stdin>, line 1)
I'm not sure who designed the system like this, but it seems basically useless, based on my experience so far. Either create a system that works, or don't create anything at all.

Command 'pytest' not found even though I moved pytest.py to /bin [duplicate]

There are already two posts on stack overflow on this topic; however, none of them have resolved or addressed my specific situation.
I have installed pytest via pip install pytest. I am able to import the library in Python as well.
The problem is that when I try to use the py.test command in Terminal, I get py.test: command not found.
Does anyone have any insight as to why I am not able to use the command in the terminal?
EDIT: It even shows up as an installed package:
$ pip list
cycler (0.9.0)
matplotlib (1.5.1)
numpy (1.10.1)
pip (8.1.0)
py (1.4.31)
pyparsing (2.0.7)
pytest (2.9.0)
python-dateutil (2.4.2)
pytz (2015.7)
scipy (0.17.0)
setuptools (7.0)
six (1.10.0)
tensorflow (0.5.0)
vboxapi (1.0)
wheel (0.26.0)
using python -m pytest will work for you.
Or if you using virtual environment and installed pytest on virtualenv you should then run py.test alongside your virtual environment.
Check this website can be useful:http://pythontesting.net/framework/pytest/pytest-introduction/
I already had the latest version of pytest on macOS with Homebrew-installed Python 2.7 and this fixed it:
pip uninstall pytest
pip install pytest
Are you on a mac with homebrew by any chance?
I had the same issue and it basically came down to permissions/conflict with the mac os base installed python. pip install would not install or link stuff into /usr/local/bin (it happened with both virtualenv and pytest).
I uninstalled python 2.7 completely with homebrew (brew uninstall python).
Next, I reinstalled python with homebrew to fix pip (it was not a symlink in /usr/local/bin/pip where it should have been linked to Cellar) -- brew install python
Then I uninstalled pip with sudo -- sudo python -m pip uninstall pip to remove the pip owned by root
Now I uninstalled and reinstalled python with homebrew again to reinstall pip with the correct permissions brew uninstall python && brew install python
Next I fixed the python symlinks brew link python
Finally, pip install pytest worked! (and so did pip install virtualenv)
I found the information in the chosen answer from this post very helpful:
https://superuser.com/questions/915810/pip-not-working-on-hombrew-python-2-7-install.
If you're not on a mac, sorry for the noise...
I may be late, but while exploring this I noticed that this can be because the Scripts folder for python is not present in the PATH.
For me this is my scripts folder:
C:\Python38\Scripts\
If the path is a problem then running pip install pytest should actually you give you the warning with the path it was added to.
This should be present in the path. If on windows, edit the environment variables and this location to the PATH.
For me the path was incorrect because of an improper installation of python
I had the same issue. I had pytest v2.8.3 installed and the binary was on my path but under the name py.test. Upgrading to v3.0.3 added the regular pytest executable to the path.
I had the same problem. I have changed the Python installed folder permission to full access. And then uninstalled the pytest and installed again.
pip uninstall pytest
In my case, I had a similar issue in ubuntu 20.04. The below solution worked for me.
Cause: Shell remembers the previous version or previously used Path, hence we need to force the shell to 'forget' the old location - with -r
hash -r pytest
Then execute the tests it should work fine.
For MAC users:
Download python universal installer for mac:
https://www.python.org/ftp/python/3.10.5/python-3.10.5-macos11.pkg
Then try to install pytest module in terminal using this command:
pip install pytest
Hope this will fix the issue. Thanks!
use the command, pip install -U pytest and install it in your cmd prompt, it will solve the issueenter image description here
I used macbook air m2, and the way I deal with this problem is:
Command in terminal in macbook:
which pytest
/opt/anaconda3/bin/pytest -> my terminal shows this
Then you got the path of pytest, in the "Command", before "pytest", add its path and following with the path of python file you wanna test.
/opt/anaconda3/bin/pytest /Users/cindyng/Desktop/Testing.py
Done, and if you cannot find the path of python in macbook, "which python" also helps, and you can put it in "Home" and "Custom Python Builder".
Hope that helps, good luck!
I Fixed this issue via below steps.
1.First uninstall existing pytest.
2.Check python version.
3.then verify pytest version is supported with python version or not via github issue tracker.
4. via sudo install pytest
sudo pip install pytest
5. verify pytest version and insatlled correctly or not.
pip list
pytest --version
6.run any test using pytest test_abc.py
I encounter the same problem, python -m pytest works for me.

Installing Django on Ubuntu 16.04, python3

I am unable to install django on python3 in ubuntu 16.04.
Here is what I have tried:
1. pip3 install django
2. pip3 install --trusted-host pypi.python.org django
3. pip3 install --index-url=http://pypi.python.org/simple --trusted-host pypi.python.org django
I keep getting the same error:
Could not fetch URL https://pypi.python.org/simple/django/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement django (from versions: )
No matching distribution found for django
I have Django installed on python 2.7, but I need it on python 3.6.
When I run
sudo apt-get install python3-django
it says
python3-django is already the newest version (1.8.7-1ubuntu5.5).
I believe this is because I have python3.5 installed with Django on python3.5, but I need it on 3.6. Python3 refers python3.6. My pip3 is up to date.
Any help is appreciated.
1st: You didn't explicitly say so, but I am assuming you are using linux based on your mention of apt-get
The simplest way to get django on your python 3.6 is to fix pip. This is a pretty good overview of how to get the libraries that pip needs based on error messages such as yours. You just need to apt install a few packages.
Once you have all the dependencies installed for pip3 to run, try installing django again.
Note: since you have python3 already, I'd make sure you are calling the right pip3, you can do this by calling:
pip3 -V
If the 'pip3' command is calling the pip3 in 3.5, then use the full path of the pip3 in python 3.6 instead.
Alternatively
You can try copying django from your lib/site-packages folder from your python3.5 installation to your python3.6 installation. The big gotcha is that you need to make sure to copy all the dependencies for django as well. You can ether look them up in the django config or you can try and use it and copy them over one at a time based on the error messages.
Unsolicited Advice:
I would strongly suggest using virtualenvs to make this process much easier. I use pyenv and pyenv-virtualenv here, and have really loved them.
16.04 is a LTS release. As such it is locked to python 3.5. You may have noticed that there were no packages in the Xenial repositories and had to install python 3.6 from alternate sources. Just be careful with that since things can break at the system level. In the end I went with building python from source and generating a django venv using.
python3.6 -m venv mydjangoproject
See this post for more details.
See this gist for a working Ubuntu16.04 Python 3.6.3 example
#allow to add latest python version-
sudo add-apt-repository ppa:deadsnakes/ppa
#update-
sudo apt update
#installing python3.6 and pip package manager-
sudo apt install python3.6 python3-pip
#update for alternative version of python-
sudo update-alternatives --install /usr/bin/python3 python3/usr/bin/python3.6 1
#configuring python 3.6-
sudo update-alternatives --config python3
#install django -
sudo apt install python3-django
#adding project name-
django-admin startproject projectname
#cd to project dir-
cd projectname
#add your ip add using vim or any editor in settings.py inside []-
nano ~/projectname/projectname/settings.py
#Run the server-
python3 manage.py runserver 0.0.0.0:8000
#run at browser using 127.0.0.1:8000

Checking whether pip is installed?

I am using Python 2.7.12 and I want to check whether the pip is installed or not. For this, in command line of Python application I wrote pip list and pressed enter. However, I get an error like:
File"stdin",line 1
pip list
Syntax Error: invalid syntax
So, how can I solve this issue and get the list of modules as an output?
Thanks
Use command line and not python.
TLDR; On Windows, do:
python -m pip --version
OR
py -m pip --version
Details:
On Windows, ~> (open windows terminal) Start (or Windows Key) > type "cmd" Press Enter
You should see a screen that looks like this
To check to see if pip is installed.
python -m pip --version
if pip is installed, go ahead and use it. for example:
Z:\>python -m pip install selenium
if not installed, install pip, and you may need to add its path to the environment variables. (basic - windows)
add path to environment variables (basic+advanced)
if python is NOT installed you will get a result similar to the one below
Install python. add its path to environment variables.
UPDATE: for newer versions of python
replace "python" with py - see #gimmegimme's comment and link
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
If you are on a linux machine running Python 2 you can run this commands:
1st make sure python 2 is installed:
python2 --version
2nd check to see if pip is installed:
pip --version
If you are running Python 3 you can run this command:
1st make sure python 3 is installed:
python3 --version
2nd check to see if pip3 is installed:
pip3 --version
If you do not have pip installed you can run these commands to install pip (it is recommended you install pip for Python 2 and Python 3):
Install pip for Python 2:
sudo apt install python-pip
Then verify if it is installed correctly:
pip --version
Install pip for Python 3:
sudo apt install python3-pip
Then verify if it is installed correctly:
pip3 --version
For more info see: https://itsfoss.com/install-pip-ubuntu/
UPDATE
I would like to mention a few things. When working with Django I learned that my Linux install requires me to use python 2.7, so switching my default python version for the python and pip command alias's to python 3 with alias python=python3 is not recommended. Therefore I use the python3 and pip3 commands when installing software like Django 3.0, which works better with Python 3. And I keep their alias's pointed towards whatever Python 3 version I want like so alias python3=python3.8.
Keep In Mind
When you are going to use your package in the future you will want to use the pip or pip3 command depending on which one you used to initially install the package. So for example if I wanted to change my change my Django package version I would use the pip3 command and not pip like so, pip3 install Django==3.0.11.
Notice
When running checking the packages version for python: $ python -m django --version and python3: $ python3 -m django --version, two different versions of django will show because I installed django v3.0.11 with pip3 and django v1.11.29 with pip.
$ which pip
or
$ pip -V
execute this command into your terminal. It should display the location of executable file eg. /usr/local/bin/pip and the second command will display the version if the pip is installed correctly.
pip list is a shell command. You should run it in your shell (bash/cmd), rather than invoke it from python interpreter.
pip does not provide a stable API. The only supported way of calling it is via subprocess, see docs and the code at the end of this answer.
However, if you want to just check if pip exists locally, without running it, and you are running Linux, I would suggest that you use bash's which command:
which pip
It should show you whether the command can be found in bash's PATH/aliases, and if it does, what does it actually execute.
If running pip is not an issue, you could just do:
python -m pip --version
If you really need to do it from a python script, you can always put the import statement into a try...except block:
try:
import pip
except ImportError:
print("Pip not present.")
Or check what's the output of a pip --version using subprocess module:
subprocess.check_call([sys.executable, '-m', 'pip', '--version'])
You need to run pip list in bash not in python.
pip list
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
argparse (1.4.0)
Beaker (1.3.1)
cas (0.15)
cups (1.0)
cupshelpers (1.0)
decorator (3.0.1)
distribute (0.6.10)
---and other modules
In CMD, type:
pip freeze
And it will show you a list of all the modules installed including the version number.
Output:
aiohttp==1.1.4
async-timeout==1.1.0
cx-Freeze==4.3.4
Django==1.9.2
django-allauth==0.24.1
django-cors-headers==1.2.2
django-crispy-forms==1.6.0
django-robots==2.0
djangorestframework==3.3.2
easygui==0.98.0
future==0.16.0
httpie==0.9.6
matplotlib==1.5.3
multidict==2.1.2
numpy==1.11.2
oauthlib==1.0.3
pandas==0.19.1
pefile==2016.3.28
pygame==1.9.2b1
Pygments==2.1.3
PyInstaller==3.2
pyparsing==2.1.10
pypiwin32==219
PyQt5==5.7
pytz==2016.7
requests==2.9.1
requests-oauthlib==0.6
six==1.10.0
sympy==1.0
virtualenv==15.0.3
xlrd==1.0.0
yarl==0.7.0

pip command is not being recognized

I am installing python and Django on my shared host server. I have followed the guide located here to install python and pip
http://flailingmonkey.com/install-django-justhost/
As I've encountered the problem of python never using 3.4.2 I've followed a different guide to install python 3.4.2 which is here
http://joemaller.com/1717/building-python-on-shared-hosting/
After I installed python, I went back to follow the first guide to instlall setup tools and pip.
I've ran all the commands it said and when I look inside python3.4.2/bin folder I see pip pip3 and pip3.4 files there so that tells me that pip was installed. However whenever I try to use pip instlal Django it says -bash: pip: command not found. I'm just wondering if I am missing a step somewhere?
The path is set incorrectly so adding so add the following to .bashrc:
export PATH=$HOME/opt/python3.4.2/bin:$PATH
And then source ~/.bashrc.
You could try to write this in consol to install pip
easy_install pip

Categories