Make Python 3.6.6 run with python3 and not python - python

I just installed python 3.6.6 on my server as python 3.7 was giving me too many issues. Unfortunately instead of showing up as python3 executable it is only python. here is the results of dir:
aclocal.m4 config.sub Include Mac Modules Programs Python setup.py
build configure install-sh Makefile Objects pybuilddir.txt python-config Tools
config.guess configure.ac Lib Makefile.pre Parser pyconfig.h python-config.py
config.log Doc libpython3.6m.a Makefile.pre.in PC pyconfig.h.in python-gdb.py
config.status Grammar LICENSE Misc PCbuild python README.rst
I have edited the env path to go to this directory
[root#server]# echo $PATH
/usr/src/Python-3.6.6/python:$PATH
and even
/usr/src/Python-3.6.6/
but obviously that wouldn't work because the python3 command doesn't even exist in the directory. I tried renaming python to python3 so it would run it. Currently the server came with python 2.6.6 and I don't want to disturb that version as I only need this for one piece of software. Though I need to use pip3 and if the system can't find python3 then pip3 command is also not found. Would it have to do with this install process?:
./configure --enable-optimizations --enable-loadable-sqlite-extensions
make altinstall
I wasn't sure if the make altinstall was screwing with it but.

python -3 -m ....
Or
py -3 -m ....
Anything wrong these?
[EDIT]
Further to your comment, it sounds like it could be one of the following:
The file you're trying to use is not in the PATH variable.
https://askubuntu.com/questions/60218/how-to-add-a-directory-to-the-path
Python 3.6 is not in its default position after installation or has been renamed after installation.
Where possible, and practicable, if you're unsure, then ALWAYS install with the relevant installation tool, e.g. apt-get. As far as I'm aware, this will automatically add the directory for Python to the $PATH variable. You can also type that variable into the CLI if you really want to manually check it is 100% in the PATH.

Related

Can not run Ansible after installing python 3.10

Suddenly I cannot run ansible.
Whenever I try any ansible command like ansible-playbook, ansible version, etc. it shows error
`/Users/myusername/Library/Python/2.7/bin/ansible: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/: bad interpreter: No such file or directory`,
Even if I let ansible run different python version, like ansible-playbook --version -e 'ansible_python_interpreter=/usr/bin/python3, it shows the same error.
FYI: which ansible returns /Users/myusername/Library/Python/2.7/bin/ansible
I guess it is related to my recent installation of python. Since I installed a python3.10 recently, The python2.7 becomes not work. Note I did not remove anything about python2.7 myself. looks like the installation of python3.10 changed python2.7 setting.
For most other application, I now pointed the system to use python3 as workaround, e.g. I set CLOUDSDK_PYTHON=/usr/bin/python3 to make accessing cloud cli works again. But for Ansible, I have not figured out how to make it work. I am using MacOS terminal.
Does anybody know how to resolve the above issue so that I can run ansible again? Anyway is OK as long as I can run ansible. Either reinstall ansible and let it use python3 instead of using Python2.7 or guide me how to reinstall python2.7 (in a right way, not messy with python3.10, currently I am scared of installing python, I am afraid if I reinstall python2.7, both python3.10 and 2.7 will be out of work then I cannot work).
Please help. Thanks.
You will have to do some cleanup on your system because somehow, Python 2.7 was removed from you system. This might have happened due to updating to macos 12.4 Monterey at some point, because Monterey 12.3 and newer removed the system-provided Python 2.7, replacing it with a Python 3.8.9 installation (/usr/bin/python3).
However, you still have stuff in your environment that reference all those Python 2.7 things, like your ${HOME}/Library/Python/2.7/bin/ansible directory.
Here are the things you can do to (hopefully) make ansible and your environment work again.
Change your shell's PATH environment.
You're probably using zsh since it's the default shell on macos. Have you ever changed your .zshrc or other environment files to add /Users/<name>/Library/Python/2.7/bin in your PATH? You will need to remove that.
Additionally, if you strictly want to use the Python 3.10 you manually installed (and not Monterey's system-provided /usr/bin/python3 which is python v3.8.9), you will probably need a PATH that looks like this...
# somewhere in your ~/.zshrc, probably near the bottom
export PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
Re-install Ansible
With whatever python3 binary you're using, re-install ansible
python3 -m pip install --user ansible
This will end up installing ansible into ${HOME}/Library/Python/<VERSION>/bin
Update PATH again to include new bin dir
Building on part (1) above, you want to include the bin directory for Python stuff in your user directory, to be able to refer to anything installed by pip install --user.
# somewhere in your ~/.zshrc, probably near the bottom
export PATH="${HOME}/Library/Python/3.10/bin:${PATH}"
export PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
Reload your shell and try to run ansible
# if you already have a shell open, run this
# to reload your zsh configs
exec zsh
# hopefully this returns the correct path!
which ansible
# and hopefully this runs!
ansible --help
Reinstall Anything Else You Need
You reference stuff like CLOUDSDK_PYTHON which sounds like you also have stuff like the gcloud module installed. Time to reinstall those with your new Python.
python3 -m pip install --user gcloud
# and whatever else needs reinstalling
Hopefully this all fixes your environment. Now you can clean up the remnants of Python 2.7 stuff from your home directory once everything else is working, as this directory has broken module installs that reference a deleted system Python anyway.
cd ~/Library/Python
rm -rf 2.7

Pyinstaller command not found (MacOS)

I've been trying to use PyInstaller on my program, scratch_1.py. The PyCharm project folder is called "idigen", which is saved in my desktop. So, I changed the director like so:
cd /Users/joelsaarinen/Desktop/idigen
then, moved on to use pyinstaller, and I get this error:
pyinstaller scratch_1.py
-bash: pyinstaller: command not found
I'm confused because when I use:
pip show pyinstaller
to verify that I have pyinstaller installed, it returns a positive result.
Is there an additional command I should be putting in when using Pyinstaller on one of my files? Might this be an issue with this specific program or the operating system in general? Thanks in advance.
This is a common problem due to the fact that you might install a different version of python and keep using an old version that is preinstalled in the machine. Here is the best solution.
First, check the version of the python that you installed. In my case, i installed python 3.5 and the machine had python2.7. If you run python on the terminal, most likely the preinstalled one is the one that will run.
Second, check the directory of your desired python version. watch -a python3 is the command to run to see your directory.
Third, set the directory as the main one to run your python commands.
alias python=/usr/local/bin/python3 does the whole trick
Lastly, reinstall pip. Download the get-pip.py file and run sudo /usr/local/bin/python3 get-pip.py * I used the path to show the reason we updated the alias*
Now you can run pyinstaller without problems
pyinstaller appears to have installed correctly, but the command is not available on PATH. You need to locate where the executable was placed.`below to find executables
set | grep pyinstaller
now modify path by this
export PATH=some_path:another_path
launchctl setenv PATH $PATH
I just downloaded the source code of pyInstaller from official website, put it where I can find it and wrote a script which launches pyinstaller.py from that folder.
For some reason, pyinstaller.py is missing in the pyInstaller installation downloaded via pip.
I had the same issue on MacOS with Developer Tools 11.4 and found two ways to start pyinstaller:
alt 1: path based solution
$ pip3 show -f pyinstaller|grep pyinstaller
will find pyinstaller in a bin path:
../../../../usr/local/bin/pyinstaller
...
So you can use one of the set-the-path-or-an-alias approaches or call via fully qualified path.
alt 2: call via python module
$ pip3 show -f pyinstaller|grep __init__
will get you a hint on how pyinstaller is defined as a module:
PyInstaller/__init__.py
...
With that capitalization, it's possible to call pyinstaller as a module with the following:
$ python3 -m PyInstaller --version
4.2
I'm using the latter now.

brew install python installs python2

I have 3 versions of python installed on my Mac. 2 of them are through brew i.e. python2 and python3 while the native version is python. the problem is when I put brew install python it installs python2 and not python. (By saying python means the version which runs on putting that command in terminal). What should I do so that if I type python my brew installed python launches.I have my path variables set correctly and the brew installation path is ahead than that of the usr/bin The problem I am encountering is that I have nltk installed through pip, pip2 and pip3 and when I import nltk in python2 and python3 there is no problem but when I do that in python it show no module found.
Try which python in a terminal to see which python will run. Then you know and can act accordingly to fix it.
ls -lsa $(which python) will let you see if it is a symlink to another location or a real executable. if a Symlink you can see where it points to and so you can follow the breadcrumbs to the final binary used.
if you run python from a terminal and in the python REPL do the following
import sys
print sys.path
you can see to which site-packages locations are pointed.
Other than that you of course have the option to use virtual environments to set up your version of python
if you really want python2 to be the default python command you can add a symlink to your ~/bin folder (create it if it does not exist)
mkdir ~/bin
cd ~/bin
ln -s $(which python2) python
chmod +x python
and make sure that export PATH=~/bin:$PATH is added at the back of your .bashrc or .profile or .zshrc file
Now start a new terminal session and try out python again it should point to brews version
Hope that helps

How to make rpm module work with (non-system) Python2.7

I have an RHEL5/OEL5 64 bit OS with native python-2.4 on it and rpm-python-4.4.2.3-27.0.1.el5 installed.
When doing 'import rpm' with python-2.4 everything works as expected.
I would like (must) to use the python rpm module with python-2.7.5 on the same machine and not sure what is the proper way of doing that.
Python 2.7.5 was successfully installed. When calling 'import rpm' I got an import error.
I've found few RPMs for python-2.7.5 however, they are not good for RHEL5/OEL5 64 bit
Appreciate any pointers/advise!
A good solution for Python 2.7 is to use virtualenv.
In a nutshell, virtualenv allows you to manage several versions of Python on the same computer (even the same user) without getting in each other's way. It also allows to have several "flavors" of the same Python version, each with a different set of modules.
The process is described in detail in the documentation.
In your case, create an environment and then use pip to install the RPM module into this environment. When you activate the environment, Python scripts will be able to import the RPM module as long as you start them inside the environment (usually, the same terminal or shell process).
This will not affect the existing installation of 2.7 nor the old Python 2.4.
[EDIT] There is no pip module for rpm-module. Depending on how the module works, you should try to download the source RPM (*.src.rpm) and modify the SPEC file until it takes your Python 2.7 for the build and installs into the Python 2.7 module path.
[EDIT2] Steps to fix the problem:
I opened the tar tar -zxvf rpm-4.4.2.3.tar.gz
vi configure -----> changed all instances of python2.5 to python2.7
./autogen.sh
gmake
gmake -n install > log
Check the log file to make sure it doesn't install in the wrong places.
gmake install to install for real

run "altinstall"ed python2.4 for nodejs install

i'm new to linux, please bear with me.
i'm trying to get nodejs running on my server, but because the default python version is 2.3, and nodejs requires at least 2.4 to install, i have done a "altinstall" of python2.4.
the python should be installed correctly, i can run it like this /usr/local/bin/python2.4, and when i do a version check -V, it shows Python 2.4.
okay so now i'm trying to continue with the nodejs installation, at the ./configure step. the problem is i'm not sure how to actually get the script to use the altinstall-ed python2.4 binary.
i've tried
./configure --prefix=$HOME/local/node -with-python=/usr/local/bin/python2.4
./configure --with-python=/usr/local/bin/python2.4
but they don't work. i still keep getting this error
NameError: name 'set' is not defined
how do i force the script to use this "altinstall"ed python2.4?
I had a look at the sources, and a ./configure --help in the node sources said nothing about specifying your python, so you could try these slightly hackier tricks:
An alias python=/usr/local/bin/python2.4 before you execute configure could work.
It that doesn't work, a symlink in a custom ~/bin directory (or similarly named if it already exists) to the desired Python:
Try creating a bin/ directory in your $HOME path:
~$ mkdir bin # <- in your home path
Then link the Python 2.4 executable into this directory:
~$ cd bin
~/bin$ ln -s /usr/local/bin/python2.4 python
Then at the node source tree, run configure with you ~/bin directory as the first directory in your $PATH:
[your node.js source path]$ PATH=$HOME/bin:$PATH ./configure

Categories

Resources