how do you run parallel code on Win10 terminal - python

In lessons we've been creating and running parallel programs on a virtual machine running Linux and we've been running python programs directly though the terminal with the command line
mpi4exec -n N python my_file.py
when we moved to a mac suit we had to run the command line
export PATH=/Users/admin/anaconda3/bin:$PATH
first before mpi4exec was a recognised commmand. After this the file would run fine.
My question is firstly, what does the mac line actually mean/do and secondly, is there a Win10 equivalent that allows me to run python code directly though my PC terminal?

yes, you can run python code same as that of linux in temrinal/command prompt.
for this you have to set the python path to the window environmental variable path by yourself or you can install the anaconda which do everything, install python, python-packages, spyder ide .

Related

makefile python script in both windows and linux

I want to run a makeFile to execute a python script that will work in both windows and Linux,
when I tried simply writing python script.py it doesn't work sometimes because some pc's had to use python3 environment variable.
how can I generalize that?

cannot activate virtualenv via python terminal

I create a virtual environment named djangoenv. I can run it with using cmd but I cannot in python terminal
this is cmd picture and this is python terminal picture
how can I run this server in python terminal?
Your script is block cause of execution policy.
running this commend on windows PS may work for you
Set-ExecutionPolicy RemoteSigned
Have you tried running your django server?
This seems to be common when using Windows PowerShell, indicated by the prefixed "PS" in your second screenshot. For me it looks the same. Note: I am using Pipenv vor virtualenv management, but I think it also uses virtualenv, so the error should be the same.
CMD:
PowerShell:
For some reason, it only shows the environment name in CMD, but not in PS. Still, I am in the same environment for both sessions.
Just try starting your server.

How do I access updated Python 3.9 in VS Code via command line?

I just downloaded VS Code this week and have run into a problem accessing different versions of Python.
When I run a python file called set.py from the command line via python set.py, VS Code is accessing the Python 2.7 version that came with my MacBook. When I run python --version it confirms that VS Code is using Python 2.7.16.
However, when I right-click in the editor and select Run Python File In Terminal it appears to be using the updated version 3.9.4. I have tested this by using an fstring (available in 3.9 but not in 2.7). The fstring code throws an error in the first method but clears fine in the second. Here's my code:
s = set()
s.add(1)
s.add(2)
s.add(3)
print(f"The set has {len(s)} elements.")
And here's my terminal with the results of both methods shown.
Does anyone know what exactly is going on, and how I can execute python files via the command line?
TIA
Specs:
I am running VS Code 1.55.2 and have downloaded Python 3.9.4 to my MacBook Pro running Big Sur 11.2.3
I have also downloaded the Python extension in VS Code and have selected Python 3.9.4 64-bit as my interpreter.
On macOS and linux, you will have a system python that tends to be old and you don't want to touch it because there are system utilities that rely on it.
You will also have the user-installed python, which here is python 3.9.
If the system python is python2, then the command python will typically invoke python2 and the command python3 will invoke python3.
In VS Code on Windows, when you launch a terminal window from the IDE, it will activate the interpreter/environment you've chosen for your project (typically by CTRL-SHIFT-P and then Python: Select Interpreter). I've noticed on Linux that it will not do this (and this may also be the case on macOS), so if I want to use a specific version or environment, I need to specify it or activate it as my first command in the terminal with something like conda activate myenvname.
Unlike in the terminal, VS Code will use the selected interpreter if you run code directly from the IDE (using Run Without Debugging or Control + F5).

Python3 installed, but why can't I run python file in terminal

I am trying to run a python3 file out of the directory the file is located in on macOS catalina.
so I type the following:
python3 <file_name>
and nothing happens in my terminal, it just starts a new line in the same directory, but no file runs.
Up until now I have only ever used a jupyter notebook to run python, but now I am trying to run VS code and run the file inside of the terminal.
Anyone know how to fix?
I just wanted to say I fixed the problem trying a number of different solutions:
I downloaded the most recent version of python, ran certificates and update commands.
I selected the new python interpreter from VS code using shift+cmd+P and select interpreter option.
I ran the file in python launcher and then again in terminal and it works fine now. Thanks for participating in helping me solve this issue.
Alternatively if anyone else has similar problems, try the steps I mentioned, or maybe try setting up a pyenv to run python files in a virtual python environment.

How to run Python script on Ubuntu, Windows and MAC

I'm making Python software using wx GUI library but was wondering how to run this script on different OS's. For example, do I need to create executable installation file or bat file on Windows and sh file in Ubuntu?
I've got #!/usr/bin/env python at the top of the file and I can seem to run it by actually double clicking it and clicking it on "RUN" on prompt window but I would like it to be more professional as the users are not programmers.
Being used to run python scripts on both linux and Windows environments, I know that you can use the same script for both environments.
Keep using your shebang in Linux, it won't be procesed in windows (as it is actually a comment :).
Once Python is installed in Windows, you can actually simply double click on the script (it will run by default in a cmd window), run it using the cmd or launch it in idle.
If you want to develop python scripts on windows however, you'll need some more tools :).
If you want to be more professional (and prevent your users to modify the code :), you can still think about creating an exe file : http://www.lyxia.org/blog/developpement/python/creez-des-executables-46
(warning, french inside), by using pyinstaller http://www.pyinstaller.org/ . Works for windows and linux

Categories