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
  Keep Application running after Python script ends PEGylated_User 0 95 Nov-12-2020, 03:27 PM
Last Post: PEGylated_User
  running python script showing an icon in the tray notification area chubbychub 1 106 Nov-01-2020, 03:52 PM
Last Post: jefsummers
  Python 3.6.10 fails when running a localized script. Mikee 2 349 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 556 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  Running script from Anaconda prompt acollins555 0 418 Jun-15-2020, 03:40 AM
Last Post: acollins555
  Python long running script - causes RDP failure to server? william101 1 378 Jun-08-2020, 08:18 AM
Last Post: nuffink
  Multiproccessing ValueError: Pool not running when running parallel functions Gilush 1 500 Jun-06-2020, 12:49 AM
Last Post: Gilush
  Use dynamic variable from parallel running python script Sicksym 0 305 May-15-2020, 02:52 PM
Last Post: Sicksym
  script works in windows but not in linux ovidius80 2 452 Apr-29-2020, 02:10 PM
Last Post: ovidius80
  Help for Windows service recycling script Rajesh_K 1 357 Apr-22-2020, 06:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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