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
  Running script on multiple files Afrodizzyjack 1 416 May-14-2021, 10:49 PM
Last Post: Yoriz
  Python script on windows 10 shuts down TamP 2 598 Mar-08-2021, 07:19 AM
Last Post: TammyP
  Error when running script on startup in Linux NoahTheNerd 0 403 Mar-07-2021, 04:54 PM
Last Post: NoahTheNerd
  Refresh data in python script while running in Terminal frankenchrist 4 769 Feb-03-2021, 09:54 AM
Last Post: Larz60+
  [SOLVED] Requiring help running an old Python script (non Python savvy user) Miletkir 13 1,314 Jan-16-2021, 10:20 PM
Last Post: Miletkir
  Need help with 3 errors when running script pythoncoder999 3 793 Dec-19-2020, 04:04 AM
Last Post: Larz60+
  Keep Application running after Python script ends PEGylated_User 0 452 Nov-12-2020, 03:27 PM
Last Post: PEGylated_User
  running python script showing an icon in the tray notification area chubbychub 1 668 Nov-01-2020, 03:52 PM
Last Post: jefsummers
  Python 3.6.10 fails when running a localized script. Mikee 2 651 Jul-09-2020, 10:25 PM
Last Post: Mikee
  How to kill a bash script running as root from a python script? jc_lafleur 4 1,400 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur

Forum Jump:

User Panel Messages

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