Install via pacman to specific version of Python - python

The default Python version for MSYS2 seems to be 3.8. I need to use 3.7 at the moment because I have to use PyInstaller and it is not currently compatible with 3.8 in MSYS2. I can download the earlier version of Python from http://repo.msys2.org/ and install it using pacman. With a fresh install of MSYS2 I run the following commands:
pacman -S glib2-devel
pacman -U python-3.7.4-1-x86_64.pkg.tar.xz
pacman -S python-pip
pacman -S python-setuptools
If I try to run a python script I am met with an error:
File "setup.py", line 15, in <module>
from setuptools import setup
ModuleNotFoundError: No module named 'setuptools'
This is due to the fact that everything installed after Python is actually installing in the default Python 3.8 location rather than 3.7:
C:\msys64\usr\lib\python3.8\site-packages
If I copy and paste the contents of site-packages into Python 3.7 and then try running a script I get the error:
File "setup.py", line 15, in <module>
from setuptools import setup
File "/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 19, in <module>
from setuptools.dist import Distribution
File "/usr/lib/python3.7/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/usr/lib/python3.7/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/lib/python3.7/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ImportError: No such file or directory
Which is supposed to be resolved via libffi, which was installed prior to Python, but likely does not go to a location that 3.7 can recognize?
Is there a way to set a specific version of Python as the default in MSYS2? Perhaps a path that can be set in the .bashrc file? I tried to set PYTHONPATH in there to Python 3.7 but it didn't make a difference as to where the packages ended up being installed to.

Go to the following URL...
https://repo.msys2.org/msys/x86_64/
Look for the version of the package you need and download it. Use
pacman -U pkgname
To install it...
The reason I know this is because gcc11 on MSYS is non-functional... it produces programs which crash and say
"During startup your program exited with code..." mentioned here:
During startup program exited with code 0xc0000139
The only workaround is to downgrade to the previous compiler which does work or use clang, which was not an option for me.

Trying to use an old version of Python is probably possible, but I think it will be very difficult. You would need to make sure all the other installed packages are compatible.
I am using PyInstaller with Python 3.8 in MSYS2 without issues. I would recommend trying to work through any issues with that, instead of trying to use older versions of packages.

Related

How do I update python on my Raspberry Pi to at least 3.6?

As some brief background information: I was origianlly trying to use Miniconda (with conda) to install dependencies that I need for my project on my Raspberry Pi. After trying to use Conda to install the SimpleAudio package, I got an error saying that it did not exist, therefore I proceeded to install this through Pip. Pip found the correct package although I get the following error message:
pi#raspberrypi:~ $ pip install simpleaudio
Traceback (most recent call last):
File "/home/pi/miniconda3/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
from pip._internal.models.target_python import TargetPython
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/models/target_python.py", line 4, in <module>
from pip._internal.utils.misc import normalize_version_info
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/utils/misc.py", line 20, in <module>
from pip._vendor import pkg_resources
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 92, in <module>
raise RuntimeError("Python 3.5 or later is required")
RuntimeError: Python 3.5 or later is required
It seems I need to update Python, although when I print the verion on Spyder IDE, it says I am already using 3.7.
Have I caused some sort of mismatch between what version my IDE is using and what the default process the terminal uses to look up the version? I noticed that it is looking for the Python version under Miniconda. If I can update If so is there a fix for this?
Please as me for more information if required (I am fairly new to stack overflow).
UPDATE:
I have been able to install the updated version of Python to 3.6 using the following instructions:
https://stackoverflow.com/a/56852714/12361146
This generally solves the scope of this question in terms of how I update Python, but I am still confused as to why Spyder IDE uses a more up-to-date version of Python whereas the terminal shows otherwise.
To answer the question of why Spyder reports a more up-to-date version of Python, here's the reason. The default versions of Python that are installed with Raspbian are 2.7 and 3.5, located in the /usr/bin/ directory. When you install Spyder, however (either independently, or more commonly, using conda), it includes its own installation of Python, which it is configured to use in the IDE, and which is located in a different directory. Hence when you compare the versions, first by entering python3 --version on the command line, and then print(sys.executable) from the Spyder IDE, they're different.
Now the issue with using pip alongside conda for updating the Spyder installation of Python is that it has the potential to mess it up quite badly, so avoid that unless you really know what you're doing. From code you posted above, you have avoided that, though, since that will have impacted the default Raspbian installation of Python, not the Spyder one. Upgrading the latter version should be done using Conda, not pip.
Hopefully you're now all up and running.
You can install newer versions of python using the package manager apt or apt-get.
Start by getting up-to-date package definitions.
$ sudo apt-get update
Then you can show details about the python3 package.
$ apt-cache show python3
When I run that now I get "Version: 3.7.3-1".
To install the python3 package and all its dependencies.
$ sudo apt-get install python3
You will still need to type python3 and pip3 when you run the commands because you are not replacing the built-in python 2.7.
Try these commands to see what you get
$ python --version
$ python3 --version
If you want to change the default python to python3 then have a look at this answer How to change the default python version in Raspberry Pi

ImportError: No module named configobj

I created .exe file using pyinstaller 3.3.1 and I got this message
Traceback (most recent call last):
File "install.py", line 14, in <module>
ImportError: No module named configobj
[8468] Failed to execute script install
I'm working with python 2.7 using conda environment. Lately I had updated pyinstaller to version 3.3.1 so this happened to me while I'm checking that the update is safe.
I have also created another .exe file from different script that uses also this import and its went well, so any help will be welcome.
I got this error from certbot on Ubuntu 20.04 (focal). On this version of Ubuntu, python 2 seems to be mostly deprecated and many things don't work when using it. Everything needs to be configured to use python3.
When I ran certbot, it was still using python 2.
File "/usr/local/lib/python2.7/dist-packages/certbot/main.py", line 9, in <module>
import configobj
ImportError: No module named configobj
Python 2 pip is no longer available from apt on this version of Ubuntu, so I was not able to install the proper libraries for python 2 using pip.
The version of certbot in apt is supposed to be for python3. (python3-certbot). The executable for certbot gets installed at /usr/bin/certbot.
After further investigating, I found that I had an older python 2 version of certbot hanging around at /usr/local/bin/certbot. Once I removed that (sudo rm /usr/local/bin/certbot), the python3 version of certbot runs just fine and is able to find all its libraries.
You need to install configobj via pip apt install python-pip

no module librepo after installing pytorch on fedora27

I had to install pytorch with conda, and next I had this error when trying to upgrade system :
sudo dnf upgrade
Traceback (most recent call last):
File "/bin/dnf", line 57, in <module>
from dnf.cli import main
File "/usr/lib/python3.6/site-packages/dnf/__init__.py", line 31, in <module>
import dnf.base
File "/usr/lib/python3.6/site-packages/dnf/base.py", line 26, in <module>
from dnf.comps import CompsQuery
File "/usr/lib/python3.6/site-packages/dnf/comps.py", line 29, in <module>
import dnf.util
File "/usr/lib/python3.6/site-packages/dnf/util.py", line 32, in <module>
import librepo
ModuleNotFoundError: No module named 'librepo'
I saw some answer that uses yum-deprecated for re install python, but it seems I don't have it on my machine. I don't want to reinstall linux another time, and I'm searching for kind an answer for that problem.
When installing pytorch via conda, it also installed cuda. Maybe it can be a problem ?
Before this, I remember (not sure, but kind of) I was running with python2.7 by default, and now it is python 3.6..
First the magic one-liner to fix things:
echo 'import sys;sys.path += ["/usr/lib64/python3.6/site-packages/", "/usr/lib64/python3.6/"]' | sudo tee /usr/lib/python3.6/site-packages/lib64.pth
I got the same error after using conda to install jupyterlab. For some reason conda installed its own version of python which shadows fedora's one. Conda's python searches libraries from /usr/lib/ while fedora's also searches /usr/lib64/. On most linux distros /usr/lib/ is a link for /usr/lib64/ or the other way so either one can be used. librepo is installed in /usr/lib64/.
My conclusions:
Fedora is not completely compatible with conda.
Fedora bug reports get closed as duplicate with links to obviously unrelated reports.
I have stumbled upon the same issue in Fedora 28. I used anaconda as root to update packages system wide, and this broke dnf with the message
ModuleNotFoundError: No module named 'librepo'
yum-deprecated did not work, although Fedora installed it for me after automatically querying for it (a bit strange that this worked since dnf and yum did not work).
In order to fix the issue, I deleted the existing libpython, downloaded the python3 and python3-lib rpms from rpmfind, and installed the new rpms
rm -rf /usr/lib/libpython3*.*
rpm -iv --replacepkgs python3-3.6.6-1.fc28.x86_64.rpm
rpm -iv --replacepkgs python3-libs-3.6.6-1.fc28.x86_64.rpm
Now I know it is better to use pip than anaconda system wide.

Mac - Python - import error: "No module named site"

Tonight I am trying to get the package called "requests" installed and have begun fumbling around with the terminal and do not have very much intuition when it comes to this sort of thing.
Computer is a mac mini, osx version 10.9.4
In /Library/Python I have 4 folders: 2.3 2.5 2.6 and 2.7.
In /Applications I have "Python 2.7" and "Python 3.4"
I can open IDLE and type 8+8 and I get 16 just fine.
Here is the error I am getting in terminal:
host-210-117:~ Mario$ python
ImportError: No module named site
host-210-117:~ Mario$ pip
ImportError: No module named site
My goal is to run this command in the terminal:
pip install requests
I believe pip is already installed. I run the file "get-pip.py" in IDLE and this is what it says:
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg
Cleaning up...
This may have something to do with paths? I would appreciate some guidance/hints/tips, thanks!
Oh and just a little more info that might help solve this question. Here is the first few lines of the program I'm running:
import base64
import hmac
import json
import requests
import time
import urllib
import os
Which gives me this error in IDLE (so I guess it importing those first few packages with no problem?) :
>>>
Traceback (most recent call last):
File "/Users/Mario/Desktop/pyak/pyak.py", line 4, in <module>
import requests
ImportError: No module named requests
>>>
***** System path list:
sys.path
['/Users/Mario/Desktop/pyak', '/Users/Mario/Documents', '/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Python/2.7/site-packages']
*** another update:
host-210-117:~ Mario$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
*** a little more info (is this supposed to happen?)
host-210-117:~ Mario$ which pip
/usr/local/bin/pip
host-210-117:~ Mario$ pip
ImportError: No module named site
*** After changing .bashrc
.bashrc: here's what in the file
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
alias python=/Library/Python/2.7/python
here is the output of running:
pip install requests
host-210-117:~ Mario$ pip install requests
Downloading/unpacking requests
Downloading requests-2.4.1-py2.py3-none-any.whl (458kB): 458kB downloaded
Installing collected packages: requests
Cleaning up...
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1435, in install
requirement.install(install_options, global_options, *args, **kwargs)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 671, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 901, in move_wheel_files
pycompile=self.pycompile,
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 215, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/wheel.py", line 205, in clobber
os.makedirs(destdir)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/requests'
Storing debug log for failure in /Users/Mario/Library/Logs/pip.log
I met the same question, and error info is:
ModuleNotFoundError: No module named 'xxx'
and finally solved by
brew install python3
brew link python3
sudo python3 -m pip install xxx
// or `sudo python3 -m pip install -r requirements.txt`
From what I can tell you have three versions of Python on your system.
The one that comes with OSX /Library/Frameworks/Python.framework/Versions/2.7/
Python 2.7 from python.org /Library/Python/2.7/site-packages
Python 3.4 from python.org
pip is installed against the Python 2.7 version you downloaded (the one you see in your Applications folder), unfortunately the default Python for your shell is the one that's bundled with OSX, and there is no pip installed there.
IDLE is also bundled with the Python that you downloaded, which is why it keeps telling you that pip is installed, but it doesn't work from the shell.
Since you are probably using the Python downloaded from python.org as your "primary" Python (after all, its the one with IDLE that you are using), you need to set your shell environment to point to this Python as default.
The easiest way to do that is to add a variable in .bashrc that creates an alias python and points it to the right binary. To do that, add this line to /Users/yourusername/.bashrc - files with . are hidden by default, so you'll have to write the entire file name in the command line to open it. Add the following line:
alias python=/Library/Python/2.7/python
Save the file and then close all terminal windows and open it again. Now type pip and it should work correctly, and then you can proceed to installing requests.
For future reference, try to stick with one version of Python. I personally ignore the bundled version and use the one from brew, but you can stick to the Python downloaded from python.org.
I fixed mine with:
brew reinstall python
It fixed all my broken paths. I think I broke it with a broken brew package that had a wrong python version dependancy or something like that.
site.py is a standard module that is run by python by default. It allows tweaking sys.path and running some code before your code starts running. It should live in the standard library and can hardly be somehow absent. However, you can disable automatic importing of the module by passing -S switch to python.
Anyway, you should somehow inspect why the module can not be imported. Try to examine sys.path list.
You are trying to install the package in '/Library/Python/2.7/site-packages/requests' but it requires root permissions to do so. This should do the trick:
$ sudo pip install requests
I did some reading. The command line,
python3.10 -m pip install pandas
as long as you have the latest version of pip updated, this will install pandas to the specific python that you wanted otherwise it defaults to the latest version installed in my case Anaconda. You can change the python3.10 for your desired version of python to install too.
sudo easy_install pip
sudo pip install requests

Possible conflicting python installations

I'm not sure if the default python installation is the one that I've been installing modules to, and if that may be the cause of a conflicting Unicode byte size compatibility error. In short, I've installed Numpy 1.7 using Python 2.7.3 and when I try to install this other program that uses Python and Numpy as dependencies, I get this error:
Traceback (most recent call last):
File "setup.py", line 20, in <module>
from weblogolib import __version__
File "/home/chris/Documents/IS/Bioinformatics-Software/weblogo-3.3/weblogolib/__init__.py", line 108, in <module>
from numpy import array, asarray, float64, ones, zeros, int32,all,any, shape
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: /usr/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString
So I guess I have a conflicting unicode byte size (2-byte vs. 4-byte). I went to check to see if I had conflicting versions of Python that could be messing this up.
python --version
Python 2.7.3
But this seems at odds with
which python
/usr/local/bin/python
When I go to /usr/local/bin I find these files (relevant to python):
python
python2
python2.7
python-config
python2-config
python2.7-config
Now I've installed numpy into the dist-packages directory of /usr/lib/python2.7/dist-packages which corresponds to what I get for python --version. But the fact that when I try which python and get a directory for python and not python2.7 concerns me that this might be conflicting when I try to install the program that uses python and numpy as dependencies.
So I guess to clarify my question(s): Are these normal files to find for a python installation or have I somehow installed three different versions? Could they be causing my error with the unrecognized symbol? Is there a way to uninstall if they are indeed extraneous versions?
Thanks for any help you can provide!
Oh and here is a link to a previous question I had, where I edited the PYTHONPATH while trying to fix an ImportError I was getting, if that might be affecting things....ImportError: No module named numpy
Here are the results of trying virtualenv:
chris#ubuntu:~/Documents/IS/Bioinformatics-Software$ virtualenv weblogo-3.3
New python executable in weblogo-3.3/bin/python
Installing setuptools.............done.
Installing pip...............done.
chris#ubuntu:~/Documents/IS/Bioinformatics-Software$ cd weblogo-3.3
chris#ubuntu:~/Documents/IS/Bioinformatics-Software/weblogo-3.3$ source bin/activate
(weblogo-3.3)chris#ubuntu:~/Documents/IS/Bioinformatics-Software/weblogo-3.3$ pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/lib/python2.7/dist-packages
Cleaning up...
The problem indeed seems to be a mismatch of Python and Numpy compile settings.
/usr/local/bin is where custom Python is installed, you should try to run using /usr/bin/python instead.
Another solution is to use a virtualenv. Try this:
virtualenv myproject
cd myproject
source bin/activate
pip install numpy
Basically virtualenv sets up a different Python installation with its own packages in the "myproject" directory. Running the "activate" command tells the system that you want to use this installation instead of the default system. This lets you have a different Python environment for different projects. Using virtualenv, each project can have its own versions of Python packages even if they're incompatible with other projects or system packages.
Note you will have to repeat the "source" command each time you open a new shell and want to use that virtual environment. Also you might have to install the virtualenv command by using your OS package manager. If this isn't possible (e.g. you don't have root access) or your OS version is too old for some reason, you can also download it manually from https://pypi.python.org/packages/source/v/virtualenv/
If you do ls -l /usr/local/bin/python* you should see that python and python2 are actually symlinks to python2.7, and likewise python-config and python2-config are symlinks to python2.7-config.
What OS are you on? This is more a question for superuser, but try something like this. Ditch easy_install and use pip if you haven't already.
On Ubuntu:
sudo apt-get install python-setuptools
sudo easy_install pip
pip install --user numpy

Categories