I encounter a problem with pip installation on linux. I've python 2.7 and 3.4, also Django in 1.7 installed. Currently I'm working on a project which uses different versions and I'm unable to install packages trough pip on python 2.7. Everything goes to directory of 3.4.
Is there any way to "force" pip to install packages in concrete version of python?
The usual, and recommended by most users, way of working with Django is to use a separate, virtual environment per project.
Use virtualenv to set up your Python 2.x environment and venv for Python 3.x. Both will install their own, local version of pip. Google lists lots of tutorials if you need help beyond the documentation.
Related
I have a Raspberry Pi 3 with Raspbian and I upgraded python version from 3.7 to 3.8. If I type python --version in the terminal the correct version appears as the system version. However none of the modules that I have installed AFTER the version change seem to work. Python gives ModuleNotFoundError when trying to import ANY of the modules that I have installed.
I can see the modules with pip freeze but Python seems to not be able to find them.
I followed this instructions to purge 3.7. I reinstalled pip after purging python 3.7 but pip as again installed in /home/pi/.local/lib/python3.7/site-packages/pip. How can I get rid of 3.7 completely?
python3.8 -m pip install SomePackage # specifically Python 3.8 should work.
More documentation here: https://docs.python.org/3/installing/index.html#work-with-multiple-versions-of-python-installed-in-parallel
Just to summarize the comments and suggestions from other answers:
The problem I have was caused by the fact that even I had set Python 3.8 as default and python -v was pointing to Python 3.8 the pip script was installing modules for Python 3.7.
The suggested solution was to use pip3.8 (or whatever version someone might have) to install packages for that equivalent Python version and that works good.
Ideally best option if someone wants to have multiple versions of python is to use pyenv. You can create multiple virtual environments with multiple python versions.
However Do not uninstall the default Python. I have also tried to uninstall the default Python 3.7 to avoid having two versions of python 3 and keeping track of which module is installed where. This was a bad idea. I did not know that many Linux distributions have applications which use the default Python. You might get a black screen and who knows what other problems see this discussion Removed Python 3 on 18.04, how can I fix my system?
I'm quite new to Ubuntu. On my machine, running Ubuntu 20.04 with Python 3.8, I'm trying to run a program which does not support Python 3.8, but it requires Python 3.7 (FYI, it is Carla Simulator).
I need pygame, but when installing it through pip (python3.7 -m pip install pygame) it raises an error:
ModuleNotFoundError: No module named 'distutils.util'
Now, I have distutils correctly installed and updated at version 3.8.2-1ubuntu1.
Is there any way for me to install a distutils version compatible with Python 3.7 without affecting Python 3.8 and related modules? Or do you have hany suggestion to get pygame for Python 3.7 and running Carla somehow? Could a virtual environment help?
My question is really similar to this one How to install python-distutils but I don't actually require distutils, I just need the program to work...
Thank you
----- EDIT -----
I tried creating a virtual environment using venv, but I got an error due tue unavailability of ensurepip. Googling it, I found it might be related to the fact that my Python 3.7 version might have been installed through Anaconda (I actually can't remember). Running apt-cache rdepends python3.7 I get:
python3.7
Reverse Depends:
python3.7-minimal
Is it safe to completely uninstall current Python3.7 and reinstall it to hopefully get ensurepip? Any suggested code to safely do it?
The easiest solution for you would be to run your program in a virtual environment where you would specify the default python version to be 3.7 I think (see Use different Python version with virtualenv for an example). You can then install all your dependencies inside this environment and not have to deal with any conflicts between the two versions on Python.
Using pyenv you could specify the python version you want to use.
for example:
create a new folder and hit:
pyenv local 3.7.2
then create your virtual env by using pipenv:
pipenv install
then start your journey to building your game.
hope it help.
I have Ubuntu 16.04 LTS with Python 2.7 and 3.5. I've set up virtual environments to access both 2.7 and 3.5 separately and everything works fine.
Now, I need to install Anaconda to access some libraries for a class I am taking. Whats the best way to do this without disrupting the virtual environments I have already set up.
Install Miniconda, a mini version of Anaconda that includes just conda, its dependencies and Python.
https://conda.io/docs/user-guide/install/index.html#installing-conda-on-a-system-that-has-other-python-installations-or-packages
You do not need to uninstall other Python installations or packages in order to use conda. Even if you already have a system Python, another Python installation from a source such as the macOS Homebrew package manager and globally installed packages from pip such as pandas and NumPy, you do not need to uninstall, remove, or change any of them before using conda.
Try using documentation of anaconda as most of the dependencies are untouched while installing it
my school told me to use python 3.2.5 for compatibility reasons as that's the version that they use, but I've found that a few modules I would like, don't work with python 3.2
I was wondering if there's a way to have two versions of python installed or if any later versions are compatible with python 3.2.5?
You can certainly have multiple versions of python installed. In my case I have coworkers that prefer Python 2.7 and so I have a virtual environment set up that will use python 2.7 instead of 3.4 (which i prefer). There are lots of useful cases when environments will save you headaches so do learn about them earlier than later.
Personally, I like to use the Anaconda distribution of python. With anaconda you can use conda create --name env_name python=3.x package package1 this will create a python environment with python version 3.x named env_name and install packages: package and package1. If you want an empty environment simply omit packages. The documentation for this can be found here.
However, as Antti Haapala points out 3.2 is not necessarily the most stable or compatible of versions. In fact conda has dropped 3.2 for environment creation, running conda create --name env_name python=3.2 returns an error.
I'm sure your school has some reason they want to stick to 3.2, but in my opinion you might be best served by using 3.3 (or later) instead.
ps. referring to your previous question about pip; with anaconda there is a command conda which accomplishes the same thing. For example you can run conda install pandas to install pandas. If a package can't be found, searching the anaconda site will give you info on how to add packages from other owners.
I was trying to setup Django dev environment on Mac and arrived into a hell. It all started when trying to install PIL, which failed after trying 15 or so different recipes I found on blogs. So I wanted to install the Python, this time 2.7, and reinstall setuptools, easy_install, pip from scratch.
After just installing Python 2.7, and easy_install with setuptools for 2.7, this all in turn created such a mess that is unbelievable. Different version of Python are installed everywhere, easy_install is installed everywhere and points randomly to different python hashbangs (sometimes to #!/usr/bin, #!/usr/local/, #!/Library/...)
Now I can't even do easy_install pip, which I always could. So I'm already in a hell and I haven't even attempted to install MySQL yet.
My question finally is did anyone bump into such problems, it would help enough to know that I'm not alone.
Second, would it be easier to set up the entire environment on Ubuntu than it is on a Mac?
Thirdly, is there any guide that can really clearly explain how to set up but also tear down the stack for Python development on a Mac?
It wouldn't hurt to run a VM with vagrant. This post should tell you more:
http://stevelosh.com/blog/2011/06/django-advice/
Of course using virtualenv should also help alleviate some of these issues.
I've gone through the same hell 2 weeks ago :)
I needed to make working python 2.7 and virtualenv on OSX 10.6.8.
You haven't mentioned virtualenv in your question but I strongly recommend it. That way you minimize amount of globally installed packages. Everything is... cleaner.
My idea is to only have following things globally:
python (from brew)
pip (via easy_install)
virtualenv (via pip)
virtualenvwrapper (via pip)
other through either virtualenv or buildout
I've just checked and pip PIL installs fine within my virtualenv.
Here are notes from this battle (gist.github.com):
#NOTE: .pydistutils.cfg seems to be not compatible with brew install python
#areas I needed to clean before installation
#clean up ~/Library/Python
#clean up .local
brew install python
easy_install pip
pip install virtualenv
pip install virtualenvwrapper
mkdir $HOME/.virtualenvs
Example .bash_profile:
#homebrew
export PATH=/usr/local/bin:/usr/local/sbin:${PATH}
# homebrew python 2.7
export PATH="/usr/local/share/python:${PATH}"
#virtualenv wrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/share/python/virtualenvwrapper.sh
Good luck!
Second, would it be easier to set up
the entire environment on Ubuntu than
it is on a Mac?
To answer this question (though I never used Mac though): I never had problems setting up a python environment for Django development on Ubuntu. Though in any case you should go with the built-in Python version if possible. Attempting to install any other Python versions usually ends up messy. Luckily with Ubuntu 11.04 the standard version is already 2.7.
I'm using django development environment on a MAC OS X 10.8 with python 2.7. I don't use virtualenv ore some other things.
With all the respect can say that there is NO ANY PROBLEMS to develop on a mac. Mac is a UNIX like system and you've probably seen that all tools for developers have MAC ports.
As for the setup mess. It's a good idea to use virtualenv. As for PIL installation. I needed to compile it with TrueType. As I'm in common with UNIX like environments it was not heavy task for me to compile PIL from sources using GCC (it's already installed on a MAC)... There are some mess with Django to setup virtualenv... There are certainly lots of articles to setup it on Google.
I use Eclipse and write all my PYTHONPATH variables there. You can forget installing everything like in Linux and try not to make anymore mess with installed tools. Try to read THIS article if you feel like you're ok to use Eclipse for your development on a MAC. It also has a recipe to avoid mess with installation of many copies of Python and other dev utils.
Yes I have had problems with MacOS. I think rather than trying to figure it out I just switched to Ubuntu. I use a mac with Ubuntu installed in VMware Fusion. I have developed on both and prefer the Ubuntu because I'm just more comfortable with installing packages and the file structure.
I love using the VM because I'm never scared of having to start over. I can get a whole new OS installed and get the packages with what I use in just a few hours. Not to mention with 6month rollouts I can do complete installs of new versions instead of updates.
Depending on your production environment, it may be beneficial to use an OS that is similar, if you can install a package on ubuntu desktop, you already know how to do it on ubuntu server.