Can't find Python when building Qt from sources - python

We are trying to build the last version of Qt ( qt-15.5.0 ) from the sources on Ubuntu 20.04. Everything is running fine until we get the following error:
Project ERROR: Building QtQml requires Python.
Python is avalaible ( version 3.8 ), we even tried alias python=python3 and adding the path to python to $PATH but it didn't help. We can't find any info on this specific problem.
What we did:
$ wget http://download.qt.io/official_releases/qt/5.15/5.15.0/single/qt-everywhere-src-5.15.0.tar.xz
$ ./configure -prefix /username/dev/libraries/qt-5.15.0/install -xcb
$ make -j8
$ sudo make install

Whilst manually setting the alias is a quick workaround, and it helps in many cases, this solution is less useful when dealing with systems that are managed in an automated fashion.
In order to come around this issue, in Ubuntu 22 at least there is a meta-package available, which solves the issue:
sudo apt install python-is-python3
Other distros may possibly have similar solutions readily available.

$ vi .bashrc
Add the following alias to the .bashrc file.
alias python=python3
Save it and source the script.
$ source .bashrc
If it didn't work, use
$ which python3
/usr/bin/python3
$ sudo cp /usr/bin/python3 /usr/bin/python
Then you are ready to build your Qt!

Related

WSL2 - How do I uninstall other, accidentally installed versions of python(3)?

I installed a bunch of python versions from a bunch of different sources while trying to upgrade from python3.8 to python3.11 on WSL2 and now I have no idea:
which ones of the installed versions I can delete (since they were wrongly installed and are not used)
how I can delete them
which one is the one I am using now as python3.11 (since I would want to keep just that one)
and which one is the system default python that should never be deleted.
In the following I'm first going to explain how I got to the point that I am at now and then explain the specific details of the problem that I'm facing trying to delete the correct versions (as in the versions that I dont need anymore) in the TLDR section.
I was trying to upgrade my version of python3 in WSL2 from 3.8 to 3.11. I tried a few guides to install python3.11.
First I followed this one which installs python3.11 using sudo add-apt-repository ppa:deadsnakes/ppa , sudo apt install python3.11 and sudo apt update.
It then proceeds to set the default python version using sudo apt update-alternatives and a few other commands. This didn't work for me however, since WSL2 said that there were no update-alternatives.
When I executed python3 --version it still said that I have python3.8.
Therefore I then proceeded to follow this guide which uses:
$ tar xvf Python-3.11.tgz
$ cd Python-3.11
$ ./configure --enable-optimizations --with-ensurepip=install
$ make -j 8
$ sudo make altinstall
After installation however python3 --version still showed python3.8. Then I found this guide to change my system to use python3.11 using symbolic links. Now it works and python3 --version shows python3.11 and my system uses it.
TLDR: Now on to my problem of not knowing which versions to delete and how to delete them properly / thorougly / without breaking anything:
which python3 shows /usr/bin/python3 and which python3.11 shows /usr/local/bin/python3.11. My /usr/bin/ and my /bin/ folder folder look like this now and my /usr/local/bin/ folder looks like this.
I honestly am so confused even, as to what folder is what, as navigating like this:
$ cd ~
$ cd /
$ cd home/myusername/
leads me back to being at ~ and inside the / folder there is the bin/ folder containing all this stuff but then inside /usr/local/bin/ there is all this stuff again. Then in /home/myusername/ there is nothing even though there should be a bin folder too according to most websites. Instead it leads me back to ~.
So any help would be much appreciated in figuring out which of those python versions I can delete now, how I do this and what all the confusion with the directories means.
Thanks in advance!

env: python: No such file or directory when building app with Xcode

When I build/run/archive my app in Xcode (on MacOS 12.3) I encounter this error:
env: python: No such file or directory
Command Ld failed with a nonzero exit code
I think I might have changed something with regard to my python environment while working on a school project or messed something up there. However, I can not figure out what is wrong.
I tried reinstalling Xcode and python (using brew and pyenv). I also relinked python using brew. But I still encounter the same error.
Which python gives the following results:
which python3
-> /usr/local/bin/python3
And in my ~/.zshrc I have the following line:
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
Any help would be appreciated! If I missed or forgot anything please let me know, I'm quite new to this.
Homebrew only installs the binary python3, just to be safe. Xcode is complaining about a lack of the binary python (note the lack of a 3!).
You have a couple of options:
When installing python3, Homebrew also creates a libexec folder with unversioned symlinks, such as python (what you're missing). Note the Caveats printed when installing it:
$ brew info python
python#3.9: stable 3.9.10 (bottled)
==> Caveats
Python has been installed as
/opt/homebrew/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/opt/homebrew/opt/python#3.9/libexec/bin
See: https://docs.brew.sh/Homebrew-and-Python
You could add this directory to your $PATH, such that python and pip become available; something like the following might suffice:
echo 'export PATH="'"$(brew --prefix)"'/opt/python#3.9/libexec/bin:$PATH"' \
>>~/.bash_profile
... although that will need to be modified according to your precise version of Python3, your shell of choice, etc.
Alternatively and more simply, although a little more jankily, you could simply manually create the appropriate symlinks:
ln -s "$(brew --prefix)/bin/python"{3,}
I had posted the same question on nativescript official github and the solution that worked for me was in the answer by the user shilik
Monterey 12.3 removes python 2. All you need to do is to reinstall
python2 back to system from this link
https://www.python.org/downloads/release/python-2718/
install python3
run 'ln -s /usr/bin/python3 /usr/local/bin/python',Create a link to Python
Add -f to be effective.
ln -s -f /usr/local/bin/python3 /usr/local/bin/python
For me the problem was with missing python
env: python: No such file or directory
BUT in the end missing was python version 2.x after updating to macOS Monterey 12.5 (21G72).
Problem was resolved by installing python from:
https://www.python.org/downloads/release/python-2718/
What I've also tried but you probably don't have to do:
sudo brew install python
sudo brew upgrade
sudo ln -s -f /usr/local/bin/python3 /usr/local/bin/python
sudo ln -s $(which python3) /usr/local/bin/python
sudo ln -s $(which python3) /Applications/Xcode.app/Contents/Developer/usr/bin/python
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Applications/Xcode.app/Contents/Developer/usr/bin/python
This took me days of head scratching, and none of the solutions I found on the internet worked.
Eventually what DID work for me was this:
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Applications/Xcode.app/Contents/Developer/usr/bin/python
I used the find command to find all instances of python in the file hierarchy:
find / -name python*
and I saw that there was a symbolic link labelled python3 in /Applications/Xcode.app/Contents/Developer/usr/bin/ that was linked to a python instance deep within the bowels of Xcode.
However there was no symbolic link labelled python which seems to be what Xcode is looking for.
So I created a symbolic link linking python to python3 and that did the trick.
For what it's worth, I installed python via pyenv which I installed through homebrew on a 2020 Mac mini M1.
In my case, created symbolic link for dev_appserver.py like below.
ln -s /opt/local/bin/python2.7 /usr/local/bin/python
ln -s /opt/local/bin/python2.7 /usr/local/bin/python2
Command location and version should be adapted to your environment.
I was able to solve this issue with the above-mentioned answers.
In my case, while I was trying npm install in my node project and was facing this issue.
Note: % brew install python is a prerequisite for all the below steps! Test if python is correctly installed by brew python info
First thing which comes to mind is if python is correctly installed and the path is set correctly.
python --version was giving zsh - python not found error while python3 --version was a success.
Next steps were to set the correct path. I did the below steps and it worked:
echo "alias python=/usr/bin/python3" >> ~/.zshrc
ln -s -f "$(brew --prefix)/bin/python"{3,}
ln -s -f "$(which python3)"{3,}
What I was missing was to run brew install python, and it worked like a charm!

How to set "python" as default

Hello can someone help me with this.
So the issue is that I started using linux and I need to make my "python3" line code into just "python". For example -- "python3 run.py" (this is now), but i want just
"python run.py". If someone can help me it would made my day
All these answers assume your system doesn't have Python 2 installed, otherwise you might cause other issues.
The recommended way if you are using BASH on Linux or UNIX, is to edit the .bashrc file in your home directory :
~/.bashrc
The '~' 'points to your home directory '/home/username'. Once you have this file open, add the following to the bottom :
alias python='python3'
Now typing 'python' will automatically run Python 3. I use this method because it doesn't require altering system files, but you can't run as sudo (which might be a good thing).
If you need to use 'sudo', create a symbolic link with the following command:
sudo ln -s /usr/bin/python3 /usr/local/bin/python
Alternatively install the 'python-is-python3' package, as mentioned by #chepner the following assumes you are using the apt package manager, and similarly does nothing more than create a symbolic link :
sudo apt install python-is-python3
1.Go to terminal type - python --version
2.Log in with root privileges sudo su
3.Execute this command update-alternatives --install /usr/bin/python python /usr/bin/python3
4. Check version again
You can install python-is-python3 package:
$ sudo apt install python-is-python3

Compiling python3.4 with a updated openssl library

I have an older version of Openssl that I no longer want to use with python3.4 programs. I have been using the following configure options
./configure CPPFLAGS="-I~/Downloads/openssl/1.0.1j/include" LDFLAGS="-L~/Downloads/openssl/1.0.1j/lib"
After compiling I print the openssl version from within a python program it will show the older version and not the one I have linked to above.
Are there other options I need to specify or do I need to alter setup.py?
You need to set CPPFLAGS and LDFLAGS before running ./configure. So, from the command line, (assuming you're using bash or similar):
$ export CPPFLAGS="-I~/Downloads/openssl/1.0.1j/include"
$ export LDFLAGS="-L~/Downloads/openssl/1.0.1j/lib"
$ ./configure
$ python3 setup.py make
$ sudo python3 setup.py install # assuming you have admin rights
Obviously, make sure you have successfully compiled openssl first, as just unzipping the source won't work. If you don't have admin access, or just choose to install everything in your home directory, I find it easier to create ~/lib and ~/include directories along with ~/bin so everything can be stored in one place.

ubuntu /usr/bin/env: python: No such file or directory

I update the kernel, after that the Ubuntu doesn't work well, PS: I try to exec "meld" command, it will report that "/usr/bin/env: python: No such file or directory",
then I exec "sudo apt-get install python" and get the result "python is already the newest version.", what should I do for it.
I'm not good at linux, can you tell me how to revert my linux to the last right status, or reinstall the python normally.
Problem scenario:
/usr/bin/env: ‘python’: No such file or directory
Possible Solution #1
If Python 3 is not installed, install it: apt-get install python3
Possible Solution #2
If Python 3 has been installed, run these commands: whereis python3
Then we create a symlink to it: sudo ln -s /usr/bin/python3 /usr/bin/python
EDIT: hi everyone, I noticed that #mchid posted a better solution below my answer: sudo apt install python-is-python3.
On Ubuntu 20.04 and newer, there is a package to fix this problem. Run the following commands:
sudo apt update
sudo apt install python-is-python3
Run apt-cache show python-is-python3 for more info.
Having been momentarily stumped by this error myself, I thought I'd post how I fixed my problem.
My problem was an error:
: No such file or directory
Which made little sense to me. My problem is that my editor had silently converted the script from Unix LF to Windows CR/LF line-termination. A rather unfortunate upshot of this is that "#!/usr/bin/env python" actually became "#!/usr/bin/env python\015" where \015 is the invisible CR character... /usr/bin/env was, then, unable to find a command "python\015" - hence the file-not-found error.
Converting the script to Unix line-ending convention solved my problem... but only after a few minutes' head-scratching.
May 2022: For anyone who just updated to Monterey 12.3 it appears the update replaces python with python3. Downloading python fixes the issues in Xcode and git command line. Be sure to read the two comments below.
For people facing the same issue with MacOS and installed python3 with homebrew:
sudo ln -s /opt/homebrew/bin/python3 /opt/homebrew/bin/python
#mchid's answer is the one you should go for it.
just FYI,
if you do this:
$ python
it will say Command 'python' not found ...
But if you do this:
$ python3, it should work.
So, just modify the shebang line
from !#/usr/bin/env python
to !#/usr/bin/env python3, you're good to go.
(which is automatically done by doing
sudo apt install python-is-python3)
This answer for android build system error
For Python 3
If you get a "/usr/bin/env 'python' no such file or directory" error message, use one of the following solutions:
If your Ubuntu 20.04.2 LTS is a newly installed (vs. upgraded) Linux version:
sudo ln -s /usr/bin/python3 /usr/bin/python
f using Git version 2.19 or greater, you can specify --partial-clone when performing repo init. This makes use of Git's partial clone capability to only download Git objects when needed, instead of downloading everything. Because using partial clones means that many operations must communicate with the server, use the following if you're a developer and you're using a network with low latency:
repo init -u https://android.googlesource.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M
you can see document in
Downloading the Source
creating a symbolic link solved the issue for me
sudo ln -s /usr/bin/python3 /usr/bin/python
Additional possible solution if the other suggestions from the mates are not working is to convert the .py scripts into UNIX format.
You can do so by installing dos2unix, before converting your scripts. You can do with something like this:
sudo apt install dos2unix
Once installed, you can convert your script accordingly:
dos2unix <filename>.py
You can read more here about dos2unix.
--
Separately, do try to run your script locally and see if it's working, you will also need to take note to include the hashbang in your script.
#!/usr/bin/env python3
Note that above is for python3, use python if necessary.
For those with macOS or M1 machines (tested on 12.5) symlinking /usr/bin/python3 will not work because it's a reference to the xcode python3 installation. Instead do:
sudo ln -s /Library/Developer/CommandLineTools/usr/bin/python3 /usr/local/bin/python

Categories