Installing Python on RHEL6.9 - No Internet, No Yum, No Pip - python

I have a super barebones airgapped machine.
It has the Python3.6.6.tar.gz from the website. It has no access to outside sources. It has no ability to use yum or pip as they're not on here.
What is the best method for getting Python3.6 installed onto here without having to transfer files over?
Edit -
I've tried
./configure
make ( or make install or make altinstall )
When I go to run python3.6 I get
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
I've tried changing export PYTHONHOME to /usr/local/ with no luck, though that did clear up a previous error related to it

Related

missing _ctypes and without yum and pkg

I was trying to install python 3.7.4 on a freebsd machine.
At the end of make install the error popped out.
ModuleNotFoundError: No module named '_ctypes'
Libffi is installed by source and its prefix was set to $HOME/lib/libffi
Attempt 1. I've tried installing cpython, and it installed setuptools successfully at the end of make install. Then when I was installing numpy by source, The same error appeared.
So I deleted cpython and tried to install the regular one again.
Attempt 2. According to this thread I added the some stuffs while doing ./configure. The full command was:
./configure --enable-optimizations --prefix=$HOME/programs/python --enable-shared LDFLAGS="-L$HOME/lib" CPPFLAGS="-I $HOME/lib/libffi/lib/libffi-3.2.1/include"
but the same error popped out at the end of make install
Attempt 3. I've tried to force install an anaconda on it, but it didn't work.
Side note 1: yum and did not exist on the machine, and I don't have the root access.
Side note 2: I've deleted every -fprofile-correction in Makefile, since the machine doesn't recognize it.
Side note 3: this is found near the end of make:
Python build finished successfully!
(...)
Failed to build these modules:
_ctypes
It is almost always a mistake for a FreeBSD user to build a software package, that's already been officially ported to the OS, himself.
What you should do instead is:
cd /usr/ports/lang/python37
make install clean

How to fix "No module named 'encodings'"

Before today, I only had a Python37-32 directory when it comes to python. I had to install python 2.7 for something, and now everything has broken.
After downloading the latest python release and clicking "update current installation" (or something along these lines), I was expecting I would have my old python back. However, I am now missing all of my imports. When trying to reinstall them with py -m pip install <package>, I ran into this:
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Whenever I typed "py" into my VScode terminal (and normal command prompt), I would get this error. What have I accidentally done to mess up everything?
I didn't "fix" my problem
I decided I should uninstall both Python2.7 and Python3.7, then reinstall the latest version. I have. It's working fine now, albeit I will need to reinstall many packages!

Python pip install gives “Command ”python setup.py egg_info“ failed with error code 1”

Edit: Yes I know this question already exists, except my question is a bit different and none of the solutions fixed it.
I do most of my Python stuff when I'm at work and not on my personal machine, but I decided to install it on my personal computer as well. I fresh installed python 3.6.1, and created a virtual environment with virtualenv. Then within the virtualenv I tried to pip install urllib (or any module) and I received the error:
(pdbot) C:\Users\user\Documents\pdbot>pip install urllib
Collecting urllib
Using cached urllib-1.21.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\setup.py", line 191
s.connect((base64.b64decode(rip), 017620))
^
SyntaxError: invalid token
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\
I read elsewhere that this error had something to do with setuptools not being properly installed. So I ran this to attempt to fix the issue:
easy_install -U setuptools
I ended up receiving an even weirder error next:
(pdbot) C:\Users\zeke\Documents\pdbot>easy_install -U setuptools
Searching for setuptools
Reading https://pypi.python.org/simple/setuptools/
Downloading https://pypi.python.org/packages/a9/23/720c7558ba6ad3e0f5ad01e0d6ea2288b486da32f053c73e259f7c392042/setuptools-36.0.1.zip#md5=430eb106788183eefe9f444a300007f0
Best match: setuptools 36.0.1
Processing setuptools-36.0.1.zip
Writing C:\Users\zeke\AppData\Local\Temp\easy_install-jhg1val_\setuptools-36.0.1\setup.cfg
Running setuptools-36.0.1\setup.py -q bdist_egg --dist-dir C:\Users\zeke\AppData\Local\Temp\easy_install-jhg1val_\setuptools-36.0.1\egg-dist-tmp-8apak7kn
warning: no files found matching '*' under directory 'setuptools\_vendor'
Copying setuptools-36.0.1-py3.6.egg to c:\users\zeke\documents\pdbot\lib\site-packages
Adding setuptools 36.0.1 to easy-install.pth file
Installing easy_install-script.py script to c:\users\zeke\documents\pdbot\Scripts
Installing easy_install.exe script to c:\users\zeke\documents\pdbot\Scripts
error: [WinError 5] Access is denied: 'c:\\users\\zeke\\documents\\pdbot\\Scripts\\easy_install.exe'
This looks like a permissions error, but I ran these both in an administrator command prompt (Windows 10) and got the same result. I am the only user on this computer and I have all admin permissions. Is this virtualenv causing an issue? How do I remedy it?
EDIT: I was able to fix the permissions issue by leveraging the python executable like so:
python -m easy_install -U setuptools
But it didn't fix the python setup.py egg_info issue. I still get this error message when trying to pip install anything:
Command "python setup.py egg_info" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-build-50tn0wlb\urllib\
I have tried both python -m pip install urllib and pip install urllib and neither work.
I had the same problem when trying to install urllib, but after doing a pip search urllib, I discovered that the problem was due to the version of urllib. From the search:
$ pip search urllib
...
> urllib5 (5.0.0) - Just increment the number and create a new lib. Never fix the original one.
At the end, a simple
pip install urllib5
within an elevated shell solved it.
Your problem has to do with permissions. The related/similar tools setup_tools, easy_install, and pip all tend to set a default set of permissions on files and folders they try to create in the package installation folder(s), rather than trying to match access permissions of the location they're installing in.
On Linux systems, where files and folders individually have permissions, this is frequently bypassed with the sudo command. On Windows, the equivalent is to run the installer as an Administrator. Since you're in the console, you have to open a console with Administrator privileges to run the pip command in.
Notable under Windows, the modules installed with pip from an Administrator console are still accessible to all users of the system that have the proper path in the PYTHONPATH system environment variable. Under Linux however, the problem is exacerbated by the fact that the files themselves may not be created with read and execute access for other users and may need to have their permissions manually modified after installation.
WARNING: urllib vs urllib2 vs urllibx
Both other answers claim that the problem is you're not specifying the correct "version" of the module in the call to pip. Neither is correct, as the error clearly indicates an installation folder access permissions violation causing the failure, but they also incorrectly recommended VERY unsafe behavior.
pip install urllib != pip install urllib5 these are two completely different packages.
The documentation for pip (https://packaging.python.org/tutorials/installing-packages/#id17) clearly says the way to specify a module version explicitly is pip install 'urllib==5'.
As part of how the package management engine implemented by pip works, running the command pip install urllib will always try to use the latest version of the urllib package, so you shouldn't need to specify the version unless you have some reason that you need a very specific version of the module.
There are two points to make in order to answer your question:
1. You are lucky you did not install that package!
The package you were trying to install was a maliciously created python package that was designed to look like a real package (in this case urllib3). If you had installed it, the package would have operated as normal except it would have sent some basic information about the system on which you installed the package to a URL (you can see more details on this here). You can read more about this fake package at either of the following links:
https://app.threatconnect.com/auth/incident/incident.xhtml?incident=5256822&owner=Common%20Community (you can sign up for a free account to view this one)
http://www.nbu.gov.sk/skcsirt-sa-20170909-pypi/index.html
Sending basic information about your systems to an unknown source isn't the worst thing you could do, but is certainly something you want to avoid when possible.
2. To properly install a package...
Specifically urllib:
To install urllib, you need to specify the version of the package you would like to install. For example, pip install urllib3.
Any package in general:
As #Elisabete Coelho suggested, you can use the pip search <package-name> feature to view the available packages. This is not perfect, however, as it may list malicious libraries like the one you were trying to install. A good guideline is that you should follow the installation instructions in a package's documentation closely to avoid any unforeseen issues. This is just an unfortunate necessity of living in a world where people make pretend python packages.

yum not working because of difficulty importing python module

I am running a CentOS 7.2 system, and I recently used pyenv to install Python 2.7.5. I am rather new to Linux, and I was under the impression that I should use pyenv to install Python so as not to interfere with the "system Python." Before installing pyenv, yum worked perfectly.
Now, however, when I try to use yum I get the following error:
There was a problem importing one of the python modules required to run yum. The error leading to the problem was: No module named yum. Please install a package which provides this module, or verify that the module is installed correctly.
I tried following the advice from the first reply of this post. When I type find / -type f -executable -name 'python2*', I get the following output:
~/.pyenv/shims/python2
~/.pyenv/shims/python2.7
~/.pyenv/shims/python2.7-config
~/.pyenv/shims/python2-config
~/.pyenv/shims/versions/2.7.5/bin/python2.7
~/.pyenv/shims/versions/2.7.5/bin/python2.7-config
~/.pyenv/shims/versions/2.7.5/envs/spyderenv/bin/python2.7
/usr/bin/python2.7
/usr/bin/python2.7 should clearly be the system Python, but when I run it and type 'import yum', I get ImportError: No module named yum. (And just to cover my bases, the first line of the 'yum' file is #!/usr/bin/python, and /usr/bin/python is a link to python2, and python2 is a link to python2.7)
It seems that somehow pyenv is screwing things up, but I can't figure out how. Thanks in advance for the help.

why I cannot run bzr explorer

I have python as seen in
which python
and also
➜ ~ brew install qt
Warning: qt-4.8.6 already installed
➜ ~ brew install pyqt
Warning: pyqt-4.10.4 already installed
but then I try to run on my OSX:
➜ ~ bzr explorer
and gets this error:
invalid syntax (<string>, line 1)
Unable to load u'bzr-explorer' in u'/Users/me/.bazaar/plugins' as a plugin because the file path isn't a valid module name; try renaming it to u'explorer'.
bzr: ERROR: No module named PyQt4
You may need to install this Python library separately.
Looks like your Bazaar Explorer plugin is installed in /Users/me/.bazaar/plugins/bzr-explorer. Rename that directory to /Users/me/.bazaar/plugins/explorer and then it should work. (As the error message was trying to tell you.)
Btw, I recommend using the dmg file from the official website (http://wiki.bazaar.canonical.com/MacOSXDownloads). Bazaar Explorer is included in it and should work out of the box.

Categories