Python Forum
running script from CLI in windows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
running script from CLI in windows
#1
hello,

I wish to run a python script, passing arguments, from command line (powershell core) without the need to write before the script name python.

I am from windows 10 and I am using anaconda.
I am aware that i can convert the .py to .exe but i am not willing because i need to make changes to it.
the script is in my path.

first from CMD I associated python script to my python.exe (i followed this https://stackoverflow.com/questions/1147...hon-in-cmd):

C:\Users\vincenzo>assoc .py
.py=Python
C:\Users\vincenzo>ftype Python
Python="C:\Users\vincenzo\Miniconda3\python.exe" "%1" %*
so now i try to run my script (wrap.py) from powershell, but it argue that i missed a package:

(base) PS C:\Users\vincenzo\Cloud\Hobby\Programmi\bin> ls


    Directory: C:\Users\vincenzo\Cloud\Hobby\Programmi\bin

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          06/03/2020    19:39       16116736 arduino-cli.exe
-a---          10/04/2019    19:13       66999808 ffmpeg.exe
-a---          05/02/2020    16:25       14153454 render_pcb.exe
-a---          06/04/2020    01:01             28 test.py
-a---          06/04/2020    01:29            850 wrap.py

(base) PS C:\Users\vincenzo\Cloud\Hobby\Programmi\bin> wrap
Traceback (most recent call last):
  File "C:\Users\vincenzo/Cloud/Hobby/Programmi/bin\wrap.py", line 6, in <module>
    import pyperclip, click
ImportError: No module named pyperclip
(base) PS C:\Users\vincenzo\Cloud\Hobby\Programmi\bin> wrap.py
Traceback (most recent call last):
  File "C:\Users\vincenzo/Cloud/Hobby/Programmi/bin\wrap.py", line 6, in <module>
    import pyperclip, click
ImportError: No module named pyperclip
(base) PS C:\Users\vincenzo\Cloud\Hobby\Programmi\bin> .\wrap.py
Traceback (most recent call last):
  File "C:\Users\vincenzo\Cloud\Hobby\Programmi\bin\wrap.py", line 6, in <module>
    import pyperclip, click
ImportError: No module named pyperclip
as you can see none worked, but i am sure that i have the package:

(base) PS C:\Users\vincenzo\Cloud\Hobby\Programmi\bin> conda list | grep pyperclip

pyperclip                 1.7.0                      py_0    conda-forge
and i was right.

I try another way and finally it works:

(base) PS C:\Users\vincenzo\Cloud\Hobby\Programmi\bin> python wrap.py
Usage: / [OPTIONS] WORD
Try "/ --help" for help.
Can someone help me to make it working this way?
wrap this_is_an_argument
Reply


Messages In This Thread
running script from CLI in windows - by aster - Apr-05-2020, 11:47 PM
RE: running script from CLI in windows - by aster - Apr-07-2020, 02:23 PM
RE: running script from CLI in windows - by aster - Apr-07-2020, 05:06 PM
RE: running script from CLI in windows - by aster - Apr-08-2020, 07:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  No Internet connection when running a Python script basil_555 8 691 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 567 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Triggering a ps1 script in remote windows server via http python request jasveerjassi 1 395 Jan-26-2024, 07:02 PM
Last Post: deanhystad
  Help Running Python Script in Mac OS emojistickers 0 367 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  Trying to make a board with turtle, nothing happens when running script Quascia 3 710 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Python script running under windows over nssm.exe JaroslavZ 0 736 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Running script with subprocess in another directory paul18fr 1 3,892 Jan-20-2023, 02:33 PM
Last Post: paul18fr
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,359 May-24-2022, 07:02 AM
Last Post: netanelst
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,842 Feb-18-2022, 01:29 PM
Last Post: pstein
  batch file for running python scipt in Windows shell MaartenRo 2 1,925 Jan-21-2022, 02:36 PM
Last Post: MaartenRo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020