Python Forum
Running this script on Windows?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running this script on Windows?
#1
Hello,

I need to run a Python script that contains the following lines :

#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3.withPackages(ps: with ps; [pandas scipy requests (python3Packages.callPackage ./openrouteservice-py.nix {})])"

import sys
import os
import pandas as pd
import requests
from time import sleep
from scipy.spatial import Delaunay
from threading import Lock
import pickle
from pathlib import Path
import openrouteservice
import json
I have the following questions:
1. What do the first lines do?
2. Can I get rid of them to run the script on Windows?
3. How do I check which packages I need to run it? Trial and error until it runs?

Thank you.
Reply
#2
(May-14-2020, 11:45 AM)Winfried Wrote: 1. What do the first lines do?
2. Can I get rid of them to run the script on Windows?
These lines is called shebang,and used on Linux.
You can delete them,i never use shebang on Linux either.

(May-14-2020, 11:45 AM)Winfried Wrote: 3. How do I check which packages I need to run it? Trial and error until it runs?
Usually there is a usage/install instruction bye the maker that use these libraries in there code.
# 3-party libraries
import pandas as pd
import requests
from scipy.spatial import Delaunay
import openrouteservice

# Standard library(comes with python)
from pathlib import Path
from time import sleep
from threading import Lock
import pickle
import json
import sys
import os
Quick demo of venv that now comes with Python.
It's virtual environments so it's like new Python instantiation that's isolated stuff,if you don't know what it is.
# Make
E:\div_code
λ python -m venv test_env

# Cd in 
E:\div_code
λ cd test_env\

# Activate
E:\div_code\test_env
λ E:\div_code\test_env\Scripts\activate

# Install
(test_env) E:\div_code\test_env
λ pip install requests pandas scipy openrouteservice
Collecting requests .....
Successfully installed certifi-2020.4.5.1 chardet-3.0.4 idna-2.9 numpy-1.18.4 openrouteservice-2.3.0
pandas-1.0.3 python-dateutil-2.8.1 pytz-2020.1 requests-2.23.0 scipy-1.4.1 six-1.14.0 urllib3-1.25.9  

# Test that it work
(test_env) E:\div_code\test_env
λ python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>>
>>> import requests
>>>
>>> from scipy.spatial import Delaunay
>>>
>>> import openrouteservice
>>>
>>> exit()
As mention Standard library modules comes with Python and need no install.
So now have all that's needed,only missing code Wink
Reply
#3
Thanks much!
Reply


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