I'm new to Python and I'm trying to understand the basics things.
Before to install the python interpreter on my computer I downloaded Deluge (A torrent client written in Python) and it works without any issue, then I thought I must had Python running but if I run the command:
python --version
I get the error saying that python is not installed on my computer. How is it possible ? How is the code from Deluge executed ?
The software you've downloaded probably has python embedded in its distribution, hence it doesn't require you to install it separately.
Also, running python --version just tells you that python executable isn't in any directories on your PATH variable. It doesn't say it's not installed.
If I look at MacOS Deluge distribution, it has python bundled with it.
Generally, you need python interpreter to run any python programs.
That's probably because what you've download is an executable and does not require Python to be executed.
Related
I have two questions:
There is an automated python script. Initially it should install Python2.7 if already installed version is lower than 2.7. (already implemented)
How can i successfully and cleanly change the python interpreter without disturbing python dependencies on the system. So that the next time any python script runs, it runs with python2.7
Linking python to python2.7 worked but it disturbs system dependencies and i cannot run modules e.g yum
Is there a way to continue with the remaining python script (after python2.7 installation and using python2.7 interpreter for rest of the code) without breaking the sequence or exiting the code?
Looking forwards to your responses.
Your best bet is to use a virtual environment. Short of that, you could try adding a "shebang" to the top of the Python script. The recommended shebang for specifying the "default" Python 2 interpreter is #!/usr/bin/env python2. Shebangs essentially allow the author of the script to specify which installation of the Python interpreter should be used when invoking this script directly (so if your script is located in script main.py, you would invoke it with ./main.py as opposed to python main.py in order for the shebang to take effect).
I am newbie with python and here is my problem. I installed python on my windows pc and as you can see on this picture, I checked it by the command python --version and it showed me the version, no problem.
But when I ran this very simple code:
my_text = "We made it!"
print(my_text)
It said to me that Python was not found! as you can see in the picture.
I searched on the internet, and add the path variable as they said in this guide:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings
but it still does not run.
Could you please give me some advise on how to solve this?
Try using python to run your .py file, like this
python test.py
If you are seeing instructions that say to use python3 to run Python scripts, it's probably because the author of those instructions uses a system environment where python is used for Python 2 and python3 is used for Python 3.
In your case on Windows, Python 3 was almost certainly installed using python as the command to run, so you should use python and not python3 to run your scripts.
I have a problem running a python script on a system that doesn't have Python installed. I know what you're thinking...but hear me out.
Some applications like C4D and Maya come with their own versions of Python. Unfortunately, they often compile them incorrectly, so modules that should import on their version of Python (e.g. 2.6 for C4D) don't work at all. I don't know why they do this, I've asked, but it appears to be due to a lack of knowledge on their part.
To use a module that won't import, you have to use a separate python installation. But I don't want to force users to install python, so I include my own python folder (2.7.6) with the modules I want to use inside and launch my script inside my custom (non-installed) python folder like this:
cmd = [my_python_path, "-E", my_script.py]
p = subprocess.Popen(cmd, shell=False, bufsize=...etc.
This works fine as long as Python 2.7.6 is actually installed on the system, but if it isn't installed, then it doesn't work. My system above isn't targeting, or using the installed python. In fact, I've moved the installed Python folder, and renamed it to make sure it isn't being used somehow, and my script works fine. So I know it is executing with my python folder.
Question 1: Why won't the python.exe run inside my custom folder unless there is an installed version of python? Is this because of some path variable?
Question 2: How can I make my python.exe work on systems, both Mac and Win, without Python officially installed?
Thanks
Just running Python.exe from custom folder doesn't tell it the specific location of many files and folders. These stuff are fixed in Windows as System Variables.
If you are copying the whole python folder, why not install python instead? It'll take same space too? Or if you really wan't to create executable use:-
Py2Exe for windows!
py2app from Mac!
Pyinstaller for both
I prefer py2exe.
I am trying to install Sublime Text 2 on my linux machine and I cannot figure out how to run the python script to install it. I am fairly new to linux and never programmed in python before. I am trying to run the python script PackageSetup.py using ./PackageSetup.py but i get the error:
bash: ./PackageSetup.py: python: bad interpreter: No such file or directory
not sure what I have to do. I have python on my machine. I can tell cause running 'python' puts me in the console.
For all I know this kind of issue can occur if you have a misspelling or mistake in the shebang. I see two ways to solve this issue: you can try to invoke PackageSetup.py via python, like python PackageSetup.py or you can open PackageSetup.py and try to find an issue in the shebang, maybe it needs to be a full path to python interpreter like /usr/bin/python not just python.
BTW, why don't you try to install it via some kind of package manager - there is a repo for debian-based distros, and I'm pretty sure that there have to be repositories for other distributives.
I need to run python in an environment where there wont be python. Is it possible to execute python as an executable in Unix Environments, like HP-UX, IBM-AIX, Solaris, Linux etc etc....
The targeted OS is AIX now.... since it does not have python support and the installation is difficult......
Thanks.
I have used http://www.pyinstaller.org/ to create an executable in ubuntu. look at their manual, it also have the cool feature of outputting just one file with --onefile. My first choice was freeze but the executable failed to run when I used some external modules - I could not solve it and I found pyinstaller to be perfect for me.