I have several PyCharm projects, each customized with the applicable Python interpreter (2.6, 2.7, 3, etc.).
On a project that is almost Python 3 code, there is a single Python 2 script.
Can the settings be configured for this particular executable file to be interpreted with a Python 2 interpreter?
You can run that Python 2 script, if it has a main, with a custom interpreter by creating a run configuration (eg. in the top menus, Run | Edit Configurations... for this particular file.
Now if there is Python 3 code in your project that depends on this Python 2 script, I don't believe you can run it, even when forgetting about Pycharm and just talking Python in general.
Related
I'm trying to launch Blender directly from PyCharm Terminal on Windows. I first use cd 'C:\Program Files\Blender Foundation\Blender 3.1\' to get into the directory containing the executable I need, and this works okay. Then I call blender.exe and expect it to launch Blender executable from the directory I am currently in. But for some reason it launches the older (2.93) version from another folder. The same steps work just right when I do all the same in the Windows cmd.exe. I've thought that the problem could be with the Python interpreter, but I use Python interpreter that goes with Blender 3.1 in the PyCharm project settings. What am I doing wrong and how can I run the exact executable I need?
P.S. I know that I can write a simple script in Python, use subprocess module, and get almost the same result, but anyway I'd like to use the launch from the Terminal if it is possible.
I want to run a Lua file on Mac through the Terminal. Python and Java have their own respective commands, but how can I run a script file for Lua on a Mac OSx through a Terminal command? I'm fairly new to the Terminal but have some experience in Lua, and can anybody help me? It would be greatly appreciated, thanks! 😃
From the terminal:
brew install lua (This installs the lua interpreter)
lua yourfile.lua (This runs yourfile.lua in the interpreter)
Disclaimers:
There are installation alternatives to brew. Google lua installation macos and use what feels most comfortable to your flow.
You could also use a shebang on the first line and make the file executable. There is more than 1 option available here. The one listed above is the best to get going fast and easy.
From https://www.lua.org/start.html
To run Lua programs on your computer, you'll need a standalone Lua
interpreter and perhaps some additional Lua libraries. Use your
favorite text editor to write your Lua programs. Make sure to save
your programs as plain text. If you want an IDE, try ZeroBrane Studio.
If you use Linux or Mac OS X, Lua is either already installed on your
system or there is a Lua package for it. Make sure you get the latest
release of Lua (currently 5.4.1).
Lua is also quite easy to build from source, as explained below....
From the Lua FAQ
... Chapter 1 of the book Beginning Lua Programming contains detailed
instructions for downloading, building, and installing Lua. Here are
simple instructions for Linux and Mac OS X:
curl -R -O http://www.lua.org/ftp/lua-5.4.1.tar.gz
tar zxf lua-5.4.1.tar.gz
cd lua-5.4.1
make all test
I suggest you also read that Chapter 1 or ideally the entire book and of course the Lua reference manual.
Once you have the Lua standalone interpreter installed you simply run it like any other command line executable
Once you have Lua installed, such as through the brew command mentioned before, you can make your script run in terminal with these few steps:
#! /usr/bin/env lua -- add hashbang header to script
chmod +x *.lua -- make your script executable
./scriptname.lua -- run it
I am running compiled c code on the Ubuntu subsystem for Windows. I would like to automate this process with a Python script that can open the terminal, send and read commands as well as closing the window.
I am trying this on Python 3.6 in Windows 10. I thought it was going to be the same as interfacing Python with the CMD but all the things I try are not yielding results. I want to know if anyone has tried to automate processes with the Ubuntu subsystem for Windows and how can that be achieved.
First, I had to find the .exe that launches the Ubuntu app, since it's downloaded from the microsoft store.
Using OS simply gives me the following result without opening the terminal.
import os
os.system(r"C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc\Ubuntu.exe")
1
Also using subprocess will open the terminal. But parting from there, how can I give it commands and read the outputs?
import subprocess
subprocess.Popen([r"C:\Program Files\WindowsApps\CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc\Ubuntu.exe"])
I think there's a few things worth mentioning here.
Firstly, I don't think you need to use Python at all. If you want to schedule your compiled C code to run at a particular time (or linked to some other condition etc.), you can do all of this within WSL. I would suggest using cron which already comes with Ubuntu. It's a scheduling daemon that can execute tasks at specified intervals.
Secondly, if you want or need to use Python to achieve this (for whatever reason), I suggest you install a second version of Python within WSL. This will allow you to easily run whatever shell commands you want e.g. to execute your compiled C code. You don't need to worry about opening an Ubuntu window and then closing it etc. Personally I would actually go further and say that you should ditch your Windows 10 Python and just go with the WSL Python - it makes a lot of things much easier, especially if you're already familiar with Linux or are using WSL a lot for other tasks anyway.
Lastly, if you still really need to automate this from Windows 10, I suggest you use the Windows Task Scheduler to schedule a .bat file which opens bash (WSL) and executes a command as per the following link:
How to run program on ( ubuntu bash windows 10 ) from windows task scheduler
(or if you don't need to schedule it, you can instead just execute the command from Python)
Hope that helps!
Every time I try to run Pygame 2.7 version I get this prompt:
Windows cant open this file:
File name: pygame-1.9.2b1-cp27-cp27m-win_amd 64.whl
To open this file Windows needs to know what program you want to use to open it.
Windows can go online to look it up automatically, or you can manually select from a list of programs that are installed on your computer.
What do you want to do?
Use the Web service to find the correct program
Select a program from a list of installed programs
How can this be solved?
I've tried many Youtube videos.
That .whl file that you mention needs to be installed with a command-line tool called pip that comes with python. Assuming you are starting from scratch, here is what you need to do to install python and pygame. Also, as a minor sidenote, you are actually installing pygame 1.9.2 on python 2.7. Assuming you are interested in that particular version of python and pygame, here are the steps you need to follow.
To install python 2.7, you need to first go to the Python Software Foundation's website here. Go to the download section by clicking on the latest link for python 2.7.12. Scroll down and download either the x86 or x86-64 MSI installer (depending if you are on a 32bit or 64bit platform respectively).
Run the MSI installer. Most of the default options should be fine, nothing too tricky here.
After you run the installer, you need to add python to the PATH environment variable so that windows actually knows where python is on your computer. To do this, you need to find the Advanced System Settings section in your control panel (how to exactly get there varies depending on what Windows version you are on).
Once you are there, click the Environmental Variables... button. Under System Variables, we need to edit the value of the Path variable to include C:\Python27\ at the end of it. If all of the path variable stuff is on one line, you need to add a semicolon to separate it from the other paths in the list.
Congrats, now python 2.7 should be installed at this point! To test it out, open up the command prompt and type python. It should open up the interpreter in the command line and should be working.
Assuming it is working, exit out of the python interpreter. In the command prompt, type python -m pip install pygame. This should automatically install pygame for you. If you really want to use your wheel file, cd to the directory where it is installed and type python -m pip install pygame-1.9.2b1-cp27-cp27m-win_amd 64.whl.
Once that is done, you should have both python and pygame installed! Test it out in your IDE of choice (I personally use Geany) and start writing some code! Let me know if these instructions are clear enough.
Recently I've started learning Lua programming language but I don't know how to run the scripts I'm writing(.lua files). Basically I'm practicing in eclipse with Eclipse LDT, but I want to run my scripts more freely, like in cmd. What do I need to do?
You can download the Lua source here or the binaries here. After that, simply install the Lua interpreter and open your command line.
There are two ways to use Lua with the shell:
directly:
lua
running a Lua script:
lua script.lua
In this post you can find various Lua editors or development environments.
Please use google or other search engines first.