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

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

Related

pyenv deletes python after installing

I try installing python with
pyenv install 3.11.0
(though this happens no matter the version) on my Raspberry Pi. When the install is running, there's a 3.11.0 directory in ~/.pyenv/versions, pyenv versions recognizes it, and the installed python is actually usable, but the dir disappears after the installation process finished.
Raspberry Pi OS - Debian GNU/Linux 11 (bullseye) aarch64
Aside from one time when it errored out, this has happened every time I tried installing, including 3.11, 3.10, 3.9 and 3.8
I have tried:
Installing python 3.11, 3.10, 3.9 and 3.8, so I dont think it will work with any other version
Reinstalling pyenv and its dependencies multiple times
One possible cause of this issue is that there is a conflict between pyenv and another tool that you have installed on your Raspberry Pi. For example, if you have another version of Python installed on your system, it is possible that this version is overwriting the directories created by pyenv.
Another possible cause is a permissions issue. If the user account that you are using to install Python does not have the correct permissions to create and modify directories, this could cause the directories to be deleted after they are created.
To troubleshoot this issue, you may want to try the following steps:
Check to see if you have any other versions of Python installed on your system. If you do, try uninstalling them and then re-installing the versions of Python that you want to use with pyenv.
Check the permissions for the ~/.pyenv/versions directory. Make sure that the user account that you are using to install Python has permission to create and modify files in this directory.
Try installing a different version of Python, such as Python 3.8. This will help you determine if the issue is specific to certain versions of Python, or if it occurs with all versions.
If you are still experiencing issues, you may want to try uninstalling pyenv and then reinstalling it from scratch. This will reset the configuration of pyenv and may help resolve any underlying issues with the tool.

How to reset Python in macOS

Currently, I feel like my Python ecosystem is out of whack. Several years ago, I had shared my computer with someone else, and now I am discovering that my machine has many versions of Python scattered about. From what I could find, starting from Macintosh HD:
anaconda
Applications/Python 3.6
Contains IDLE, Python Launcher, etc...
Library/Python/2.7/site-packages
This contains things like pip and wheel (I am unsure what this is)
Library/Frameworks/Python.framework/Versions
This contains two folders, 3.5 and 3.6.
System/Library/Frameworks/Python.framework/Versions
Inside here there are many alias folders, all which point to 2.7
Is all of this supposed to be normal? I am trying to run Python from the terminal, yet I have been getting messages such as ImportError: No module named site. pip has also not been working.
Is there a way for me to reset the Python on my machine to just that which comes with macOS? I feel like starting over from a blank slate would be helpful, since I want to get things setup in some type of comprehendible way (e.g. a way in which I've set things up so I know what is on my machine instead of many random things put on it by another).
This is very normal. you have a preinstalled python2.7 which comes with macOS and another one "Anaconda" which has installed manually. You first need to check what is your default python path (version) on your macOS, I mean if you are using anaconda or the default pre-installed python2.x. To remind you can check like below:
python --version
output (for me): Python 3.7.6
then if you want to change it to another version/or use another version under conda you can check these two answeres of mine.
How to add anaconda to PATH?
and here:
How to set the default python3 to python3.7?
It is normal that when you install a package for your default python version you don't expect it to be installed on the other one too. Normally it is better to install python2.x as an environment of conda and switch between two environments with "conda activate py2" and "conda deactivate" to go back to your default version. for each of them, you need to be in the environment and then use pip.
if pip is not working, it may need to be installed. On macOS, as you remember, you can use
brew update
brew install pip
or "easy-install" instead of brew (or whatever you use for installation).

Four different python version installed

I am starting to learn Python on my Mac and use VS Code. At the bottom left corner I can select the Python version. Apparently I have four versions installed.
I know that macOS already has one installed (I am assuming it is the one in /System/Library/..). I must have (accidentally) installed the other versions.
What is the safe/recommended way to set up Python3 on Mac for development (I only want/need one version 3.xx)?
Where should I install pip3?
I don't want to mess around with the system's python version, but delete everything unnecessary.
Thank you for advice!
Do not delete python2.7 as it may be used by system. Other than that, whenever you want to create any project in python is recommended to create a virtual environment, this way you can always separate what version will every project use and what libraries will you install for a specific library. More infor https://docs.python.org/3/tutorial/venv.html and how to uninstall python from mac https://osxuninstaller.com/uninstall-guides/properly-uninstall-python-mac/

How can I install multiple copies of Python 2.7 on the same machine?

I want to install Python 2.7 in two places at once on my Windows machine. For example, one in c:\python27 and another in c:\myproduct\python27. The official installer refuses to let me do this. If there is already an installation when I run the installer, it prompts me and asks if I want to Change, Repair or Remove the existing installation.
The TARGETDIR trick mentioned elsewhere on Stackoverflow doesn't work either - I get the same result if I type the following into a cmd window:
msiexec /i python-2.7.8.msi TARGETDIR=c:\myproduct\python27
So, is there anyway to install Python 2.7 twice on my Windows machine?
Reasons I want to do this are:
My product requires a 32-bit version of Python 2.7 to be installed because it uses ctypes to load a 32-bit DLL. If the user already has a 64-bit version of 2.7 installed, I don't think it is safe to install the 32-bit version over the top.
Relying on the users pre-installed Python 2.7 is bad because they might uninstall it later. That would stop my product from working.
It reduces the complexity of testing my product if I can make its installer always install a known version of Python. I can rely on it being in a known state.
I'd like to add the pyreadline module to the Python install that is part of my product. I suspect most users would rather that I did not mess around with their Python install.
When a user uninstalls my product, the Python it installed should also be removed. If I installed Python in the standard place the user might come to use it for other purposes and be surprised when it goes missing when they uninstall my product.
It appears that you should be able to install the 32 bit version of Python 2.7 in another folder when the 64-bit version is already installed. See How do I install Python 2.7.3 32 bit and 64 bit on Windows side by side for a description. However it may be tricky to automate this, you might have to get users to install it themselves.
I would suggest you ask your users to install Python 2.7 32-bit, and give them instructions on how to do it if they already have a conflicting 64-bit version. Then in your installation you:
Ensure that virtualenv is installed (and install it if it is not).
Create a virtualenv in your application folder.
That addresses everything except the second item on your list and I think you simply have to accept that no matter what you do, if someone removes a component that you need your application will fail. If they do that they can use the 'repair' option on your installer from which you can either reinstall the missing Python or tell them that's what they need to do.
To install virtualenv I would first install pip (see https://pip.pypa.io/en/latest/installing.html for instructions, you need to download get_pip.py and run it with the Python 2.7 interpreter), then just run pip install virtualenv.

Using Virtualenv to install two versions of a program

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.

Categories

Resources