Running or compiling a Python script on Windows - python

I want to modify this Python script on Windows 7.
https://github.com/Jeremy1980/LDBoxer
The original author seems to have compiled the program into a Windows executable. Is it possible to run the script without compiling it? I tried the following at the command prompt:
python LDBoxer.py
But Windows says it does not recognize 'python'. What do I need to install and what is the correct command line syntax? According to the docs, this is the correct way to run the executable:
LDBoxer_2017a.exe ldraw_library_location ldraw_model_location_for_conversion
Thanks.

You need to make sure you have python installed, then make sure you are running the correct python compiling command. Sometimes when installing python 2 you need to run the command python2 or python27.
You can install python here. It looks like they wrote it with python 2.x so I would recommend installing python version 2.7 unless you want to manually convert it to python 3.x.
You should be able to run the .exe just by double clicking, or right click then run.

Related

vsCode won't recognize python installation, but does?

When I put "py --list" in the terminal I get this:
Installed Pythons found by C:\Windows\py.exe Launcher for Windows
No Installed Pythons Found!
I set my environment variables. I actually got VS Code to run some code I threw together that didn't use any imports, but now that I'm trying to use any python commands in the terminal, I'm getting errors. What gives?
python should work, since it is finding installations.
If you are working on Windows, very often it's all about permissions. Try running your terminal and VSCode as administrator! Worked a lot of times for me, also with other languages.
Please ensure that you have installed the python extension and selected the correct python interpreter (Ctrl+Shift+P and type Python: Select Interpreter).
If this didn't work, you may have to reinstall python.
Read the document about Vscode-Python for more details.

Git-bash using wrong version of Python

I am new to git-bash and am currently trying to make the Git Bash use the correct version of Python. I just installed version 3.8.1, but Git is using the 3.7.3 version.
When I run the which python command, it displays the directory of the 3.7.3 Python as expected. How can I switch it so that it is using the updated version?
Let's say, for example, the location of the Python I want to use is /c/Users/tom/Python3.8.1/python.
I am tried to solve this by searching online and I came across a post that suggested I use the following command:
PATH="path to executable python":PATH
But that did not seem to work as after I ran that, it would no longer let me use the which python command

I changed "python.exe" to "python3.exe" but now pip returns an error, how can i fix this?

So in order to make my life easier, I changed Python 2.7 to "python2.exe and Python 3.6 to "python3.exe". I then added them to my path and am able to reference them in which python2 opens Python 2.7 and python3 opens Python 3.6.
This is exactly what I want but now since I changed the names the pip command returns this:
Fatal error in launcher: Unable to create process using '"'
I still want to be able to reference python3 and run Python 3.6, but I need pip to work. Do I change a pip file to reference it? or is it something else? Please help if you can.
I strongly recommend you change the names back, because numerous scripts (pip likely included) expect the original filename.
To make your life easier when launching python files on windows, python comes with a more flexible solution. If you have a recent python3 installed on windows, the Python Launcher for Windows should be installed as well. That means you can run python 2 and 3 scripts with a py <file> command. The launcher respects shebang lines specifying the python version or you can pass a flag to choose the version manually: py -2 <file>

Python code in OSX Terminal not compiling right

So I am trying to teach myself to program in Python while on spring break and I have run into a roadblock. I can get my code to compile in PyCharm, but I would really like to get it to compile correctly in Terminal because vim is my text-editor of choice. Does anyone have any idea of why my code may not be compiling correctly?
Here is my code compiling correctly in PyCharm
Here is my code compiling incorrectly in Terminal
Thank you in advance for any help.
Any recent OSX version comes with Python 2.7 as a standard. When you install Python 3.x, you have both versions on your system. The standard way of using python -command- in the terminal calls Python 2.7. You can call a command using python3 -command- instead to use Python 3.x. You could set an alias on python3 in .bash_profile to call it instead when you use python.
You have configured PyCharm to use an installed Python 3, but at the terminal you appear to be using Python 2. There is a difference in how the two versions output the results of print. Try modifying your terminal session to direct your path to use the installed Python 3 instead of the installed Python 2.

How can I make the "python" command in terminal, run python3 instead of python2?

I'm just starting to learn Python and did search around a little, so forgive me if this has been asked and answered.
When running scripts through the command line/terminal, I have to type "python3" to run the latest version of Python. With Python 2.X I just use "python".
Is there a way to run Python 3 just using "python"?
It may seem a little lazy, but I'm mostly just curious if it is possible or if it will break anything unnecessarily if I could in fact do it.
If you are using Linux, add the following into into ~/.bashrc
alias python=python3
Restart the shell and type python and python3 should start instead of python2.
If you're using Windows then you can use the Python Launcher For Windows.
This will allow you to use the py command to select different python installations such as:
py -2.7 # Runs Python 2.7
py -3.3 # Runs Python 3.3
py -2 # Runs the latest version of Python 2.x (so if you have 2.6 and 2.7 it will run 2.7)
Similarly you can set a shebang in your python files as demonstrated below:
#! python3
print('Hello World!')
If you now run that file (let's call it test.py) with py test.py it will automatically run with Python 3. It gets the Python installation to use from the shebang at the beginning of the line.
What you probably want is to customise the default python version though. This will allow you to set the default actions if you just call py on it's own.
Once you installed python 3 in your Mac, "python3" command will be registered into the environment variable automatically. So if you need to run your python 3 file just do that:
python3 your_file_name.py
I hope this help you.
Sounds like you have python 2 and 3 installed and your pythonpath is pointed at python 2, so unless specified it uses that version. If you are using python I would suggest setting up a virtual environment (virtualenv) for each project, which means you could run whatever version you'd like in that project and keep all dependencies contained.
According to PEP-394,
"for the time being, all distributions should ensure that python refers to the same target as python2".
On *nix systems, there are three links to executables of python command line interpreter named
python, python2 and python3 in directory /usr/bin. The python link points to python2 according to the PEP, but you can change it to point to python3 by creating a new link to python3 and renaming it to python. Also, you have to delete the old python link.
on raspbian linux in the terminal i just run it by typing python3 file.py or just python file.py for python 2

Categories

Resources