How to determine if Python is available in HPUX system? - python

How can I know if the environment that I am in (some version of HPUX) has python installed?

If python is in your PATH-Environment variable (if it is properly installed, it should be), you could use one of the following three:
python --version
which python
Whereis python
Calls python --version
Shows the path that is called when using python
Shows all paths to python
If you are unlucky, it is not in your PATH and you actually have to search the whole system to be sure it is not installed somewhere.
find / -name python

you can use the swinstall command to list installed packages:
http://www.bga.org/~lessem/psyc5112/usail/man/hpux/swinstall.1.html
and as #jacob said the which ,whereis and find commands are very usefull

Related

Finding Python3 install location

For my project I'd like to be able to dynamically load and use a Python 3 shared library, if one is installed on the system (any version >=3.2). If more than one Python 3 version is installed, it would be nice to know which one is the default (i.e. the one that gets used whenever user types python3 in the terminal).
On Windows, Python install locations can be discovered via the registry, however, I am uncertain if the same can be done on MacOS and Linux. While python3 executable can typically be found on PATH, there seems to be no general way of locating Python's shared library?
Edit: To clarify, I am looking for libpython3.x.so (or libpython3.x.dylib), not the main python executable.
Also, I'd like the discovery method to be portable: it should work on different Linux distros, and for different package managers on MacOS, so saying e.g. "It's in /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/Python" doesn't cut it.
In shell on MacOS or Linux, type:
which python and/or
which python3 to get your answer
Example on a VM on my machine (under Docker):
uwsgi#08c2ed391dae:/src/psf$ which python
/usr/bin/python
uwsgi#08c2ed391dae:/src/psf$ which python3
/usr/bin/python3
Have you tried :
'''
>>> import sys
>>> sys.path
'''
That shows lib path.

After switching to Python 3.6.5_1, the displayed version is still 3.7.2

I am trying to use Python 3.6.5_1 for OpenCV, so I have switched Python versions using "brew switch python 3.6.5_1", but after checking my current version of Python using "python --version", I apparently am still using Python version 3.7.2. Any solutions? By the way, this is the tutorial I am following: https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/
Check your python path to see where your python executable is being stored---which python in terminal. I bet it's still pointing to your 3.7.2 directory's python.
If you are switching between python versions, virtualenv can be used to initialize isolated environment with a specific python version.
virtualenv -p [preferred-python-version] open_cv_project_env

How to use and install all the libraries of Python3?

Using Ubuntu 16.04.
I was doing development in Python2.7, although recently moved to Python3.5, both of which come by default. The problem is, I find all the python libraries have to be reinstalled or downloaded for the next Python3. Also, the behaviour of Python seems weird because to execute the same script in python3, I have to enter in terminal
python3 script.py
which is different from other applications where I do not have to give the version number. Anyway, the questions I am trying to find answers are
To what extent are the libraries, packages (such as pip etc.) shared between 2.7 and 3.5? Or do I need double installations (and double the space) for everything now? A bit space limited in my old laptop.
Most of the installation instructions and commands I find online do not specify whether they are for 2 or 3. Given that I have two versions, how do I control/make sure they go to 3.5?
Is it advisable and possible to completely remove everything related to 2.7? Can I keep working with 3.5?
The first thing you need to know is that all official libraries and python tools for python3 got the "3" character to separate them from the previous versions. So, you need to use pip3, and not pip, python3, not python, and the packages are called python-pygame, not python-pygame.
So, to answer to you in order:
Yes, the you have to double the space needed if you decide to use both python2 and python3
Usually, if in the tool name there is 3, it is for python3, and if not it's for python2
Python2 and python3 are completly indipendent (different path, indipendent versions, etc.) so having python 2.7 installed doesn't affect python3 BUT since python 3 is the next version of python 2, it makes it obsolete (in my opinion) so if you don't have enough space for both, keeping python2 is absolutely not needed nor useful
If you want to control your python execution then you have various method or techniques:
For downloading packages according to version
You can use pip{version-name} to download the libraries. Like if you want to download library of python 2.7 then write
pip2.7 install package-name
for python 3.5 then use
pip3.5 install package-name
For execution of program:
If you want to execute the program accoridng to you choice of version then just use
python{version-name} script.py
eg:
python2 script.py
python3 script.py
or you just write down the path of your python version on the top of script. Please refer this for more details:
Why do people write #!/usr/bin/env python on the first line of a Python script?

Use system python in homebrew

Is it possible to use system python in homebrew?
I have python 2.7.5 installed on my mac, but when I try to install any homebrew package with python in dependencies, it starts loading python 2.7.9.
It is important for me to use system python because of lots of installed python packages.
What version of python homebrew uses depends on two things:
Where the python alias points to.
What the python path is in the formula.
In most cases, homebrew forumlae simply use the python command, and does not specify a python path. If it does, then it is usually /usr/bin/python.
So, you can fix the problem in two ways:
Change the homebrew formulate to point to the right python interpreter of your choice.
Change where the python command points to.
The first option is problematic, since it means that you need to go into your Cellar folder, and alter things. This is not nice, and usually not required.
A better alternative is to point to the right python command. This is where pyenv comes in handy. pyenv is a command line tool that helps you manage different versions of python. Follow the instructions here:
https://github.com/yyuu/pyenv-installer
to install it.
Once that is done, change your python command to whatever version of python you'd like it to point to.

Uninstalling Python 2.7 on OSX 10.8.4

Main problem:
I've installed recently Python3.3 - If I run now in Terminal: python script.py (where script.py is coded in version 3.3) I'll get a python 2.7 output e.g.:
print('String',Var) --> ('String',Var)
Instead of:
print('String, Var) --> String Var
How can I uninstall Python 2.7 easily with Macport (without reading through Shell commands (time restriction)?)
This one didn't worked.
Second (smaller) problem:
If I type in Terminal python, I'll get python2.7 idle as output. How can I change this, so that command python refers to python3.3 (instead of using the command python3)
(About me:
Python2.7 novice, absolutely no Shell knowledge, OS X 10.8.4 User, Xcode and Macport installed.)
Bad idea to uninstall the pre installed version of python. Better idea is to alias python to whatever you want in your bashrc/bash_profile.
In your home directory, aka ~, you might already have a .bash_profile(If you don't have one, you can make it). You can edit that with your favorite text editor and add alias python='python3' Or whatever you want called whenever you type python into bash.
(FWIW Homebrew is the new hotness, you might want to look into it as well)
I agree that it is bad idea to uninstall Python 2.7, just use following commands:
To list available Python versions:
port select --list python
To select desired version:
sudo port select python desired_version_from_list
This is proper and easy way to do it in MacPorts.
DON'T UNINSTALL PYTHON!!
It will mess up everything --> may be crash your OS. I tried that in Fedora 17 and it failed my package manager as yum is build in Python. One many great thing about Python is it supports multiple versions at once in the same platform which you already experienced.
Now, to resolve your problem do Edgar suggested.
Also, while writing your python code do this:
#!/usr/bin/env python3
print('Hello world!')
Then,
python hello.py would run code in python3.

Categories