Using Virtualenv to install two versions of a program - python

so I have a question about installing multiple versions of a single program. Apparently I need to use Weblogo-3.3 for one part of my project, but another program I'm using for a different part uses Weblogo-2.8.2 as a dependency, and cannot work with 3.3. This is...problematic, as I need to do both parts. Both use python 2.7.
Is there any way I can use a virtual environment to selectively install and run Weblogo-2.8? I'm concerned that even if I do that and try to run the program that uses it as a dependency, it will try and call the Weblogo-3.3. Won't they both be in python's dist-packages folder and cause conflicts?
I was about to try to install it with Virtualenv, but I didn't want to mess up my current installation of Weblogo-3.3 so I was going to hold off until I knew for sure. Thanks!

This is exactly what virtual environments are for.
Create your virtual environment and activate, then any 'pip install' or 'easy_install' that you do will only affect that environment, not your site.
If I were you once you get 2.8 working, install 3.0 in a different virtenv and then think about deleting the site-wide Weblogo.

Related

Would it be dangerous to uninstall Python

I plan on uninstalling and reinstalling Python to fix pip. I, however, have a lot of python files which I worked hard on and I really don't want to lose them. Would my Python files be okay if I uninstalled Python?
If you are using Linux and a distribution like Ubuntu, you will definitely break the OS. Don't do it.
Moreover, there is no evidence that your installation is broken because of Python, and you may probably not solve your problem.
Your Python files are not specially managed by Python itself. If you uninstall Python, source code files (files with the .py extension) won't be affected.
There's no harm I can see in overwriting a pip installation. So, just follow the instructions and let us know if you have further problems:
Download get-pip.py.
Run python get-pip.py and get on with the rest of your stuff.
Before uninstalling python, make sure all your python applications support the new python version.
My suggestion is to create virtual environments in your system to use multiple python versions
Try Anaconda - https://www.anaconda.com/ to create multiple virtual environments, where you can run a python version on each environment.
It depends on whether you installed the Python or it came with the OS.
If you installed Python, it’s no problem at all — your files are safe and uninstalling Python won’t touch them.
If you’re planning on uninstalling the Python that came with your OS, I’d advise not do do that — it could cause a whole lot of trouble. Instead, you could install a new version of Python into your user directory and link to it by adding its location to the PATH variable used by your shell.

Module or Incorrect Python Version Problem?

I'm installing a bunch of python modules on my system that are specific to this code I am going to be working with. Specifically, I used pip install pyda to get the pyda module. To make sure I had gotten all the modules, I went through and ran some of the code snippets, and came across the following error:
ModuleNotFoundError: No module named 'pyda.utilities'
I tried using pip install pyda.utilities, but that honestly doesn't make sense, it should have just come with the pyda module. According to this website https://pypi.org/project/pyda/ it seems like it should come with the package. I tried determining if I just installed it in the wrong python version, but I'm having a difficult time forcing it to use the specific python version that I installed the module in (specifically, I tried to create an alias for /usr/bin/python3.7 or something like this as I have seen on other websites, but it just fusses at me that this is simply a directory, incredibly unhelpful because I can't find the corresponding executable, so I'm a bit confused here).
This is a very long question likely with a very simple answer, any thoughts or help on what the issue might be would be appreciated.
Edit: I have determined that it's a package problem, not a python problem. The command 'pip install pyda' is not actually installing everything, oddly enough, which is why it cannot find the pyda.utilities module. Unfortunately, I think this means I will have to install the package manually. I will keep this question posted because of the useful answer on virtual environments, so thanks everyone.
The answer is indeed straightforward. As #Chris indicated in the comments, start using virtual environments.
It's not as complicated as it sounds and there's plenty of tutorials on getting started with virtualenv for Python, like https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/26/python-virtual-env/
The basic steps:
check you're using the version of Python you want in your virtual environment
if you don't, change directories to where it lives
ensure you have pip and it works
check if you have virtualenv and if you don't pip install virtualenv
create a virtual environment virtualenv /your/env/folder/here
activate the virtual environment with /your/env/folder/here/Scripts/activate
After that, just install the packages you need with pip and they will end up in your virtual environment, with no interference from other Python versions or packages.
Check your python version, if it does not work restart your computer and try run setup.py install on the python command line

should jedi be install in every python project environment?

I am using jedi and more specifically deoplete-jedi in neovim and I wonder if I should install it in every project as a dependency or if I can let jedi reside in the same python environment as neovim uses (and set the setting to tell deoplete-jedi where to look)
It seems wasteful to have to install it in ever project but then again IDK how it would find my project environment from within the neovim environment either.
If by the word "project"you mean Python virtual environments then yes, you have to install every program and every library that you use to every virtualenv separately. flake8, pytest, jedi, whatever. Python virtual environments are intended to protect one set of libraries from the other so that you could install different sets of libraries and even different versions of libraries. The price is that you have to duplicate programs/libraries that are used often.
There is a way to connect a virtualenv to the globally installed packages but IMO that brings more harm than good.

why are there multiple pip versions in my Python scripts folder?

I have a variety of different Python versions installed on my Windows system- a 2.7 version, a 3.5 version, and a 3.6 version (there are a bunch of different packages that only work with one version, or are too buggy in the 3.6 version, etc.).
Long story short, I'm trying to keep my all my pips and python.exes in order. I've added my C:/Python35 and C:/Python36 and their Scripts folders to my path, but I also want to make sure that I am using the right pip from my command line (for example, I don't want to pip install pyinstaller to the 3.6 version, since Python 3.6 doesn't play well with pyinstaller as of right now.
I see that inside my Python3x/Scripts/ folder, there are three different pips available: pip, pip3.5, and pip3.
So whenever I want to install a module for 3.5, I plan to issue the following command pip3.5 install package_name. Whenever I want to install something for 3.6, I'd use pip or pip3. Seems like a decent enough plan to me.
However, can anyone confirm if the three pips are all the same executable? If so, I'd like to delete pip and pip3 so that I don't accidentally confuse it with my Python 3.6 pip- is this acceptable practice or am I missing something? This SO post provides some insights but doesn't explain why there's multiple pips in the same folder. Also, why are three separate pips provided? Is it simply for convenience from the command line?
Within the same python installation all the different pip files you find should be the same executable, there is the multiple versions simply to help keep everything in order if there are multiple installs of python on a single computer.
I personally only have the main version of python I use for development set to my PATH variable on my windows laptop and then if I need to do anything to a different python I instead link directly to the necessary file with something like C:\Python36\Scripts\pip3 install natsort but that is simply personal preference and my way of organizing.
If you do have them all on path you can then simply call out pip3.6 install <package name> or whatever python version you are using
The difference between them is that each one install the package in its own folder, for example if i type pip install Django, it will be placed for python 2 version, but is a little bit complex when you have multiple version of python3 like you showed, the solution: Don't delete the files and makevirtualenv when you're working, that avoid problems.
This prevents dependency issues with different versions of Python. You also check out virtualenvwrapper which is a convenient way to manage your virtual environments
If you want to manage the version with virtualenv
virtualenv python2_project -p usr/bin/python2.7
virtualenv p35_project -p usr/bin/python3.5
virtualenv p3x_project -p usr/bin/python3.x

New python versions add to the existing ones, rather than upgrading

I'm new to python. I installed python3.4 on OsX some time ago and now I installed python3.5 using the installer you can download from the site.
I noticed that in /Library/Frameworks/Python.framework/Versions/ I have both 3.4 and 3.5. I wasn't expecting that - I was expecting an upgrade where 3.5 replaced 3.4
So, if I run python3.5 and I try to import the packages I installed when using 3.4, they are not found. Furthermore if I use pip install to reinstall them, it says the packages are already installed, therefore I can see that it's pointing to the 3.4 version.
What I'm doing wrong? I supposed that installing the new python should upgrade my existing installation (bringing installed packages with it) rather than add a completely new install.
I'm not sure what to do now:
Should I keep every old version?
Should I manually change which pip
is used every time?
(is there a more streamlined update procedure
for next time?)
A lot of Python packages are 3rd party. The community is always moving forward and this may take some getting used to!
That said, my recommendation is to start using venv. It gives you (mostly) isolated Python virtual environments in which you can install whatever packages you like (via pip) without polluting the global installation. This also allows you to configure various virtual environments with varying packages and versions. It's really handy!
Link:
https://docs.python.org/3.4/library/venv.html

Categories

Resources