Use wget or curl from python in Windows CMD - python

I'm pretty new to Python. I have installed Python 3.7.3 on my Windows and would like to use CMD to run a .py file.
The commands are like py xxx.py and it is actually for downloading some files from a server.
When it asks "Is it OK to download", I hit yes.
Then a message appeared.
The script will need curl or wget on the system, please install them
first before running the script !
The program will exit then.
But when I try to run pip install wget this message appears:
Requirement already satisfied: wget in
c:\users\qin_l\appdata\local\programs\python\python37-32\lib\site-packages
(3.2)
And when I input py -m wget xxx.file, I can download the file (not the one I want)
I guess the part that cannot go through windows is
# Check if curl or wget commands exsit on your computer
if sys.version_info >= (3,0):
status_curl, result = subprocess.getstatusoutput('which curl')
status_wget, result = subprocess.getstatusoutput('which wget')
else:
status_curl, result = commands.getstatusoutput("which curl")
status_wget, result = commands.getstatusoutput("which wget")
And correspondingly
if status_curl == 0:
cmd='curl -g "'+cmd+'" -o '+ ncout
elif status_wget == 0:
cmd='wget "'+cmd+'" -O '+ ncout
else:
sys.exit('\nThe script will need curl or wget on the system, please install them first before running the script !\nProgram will exit now !\n')
It seems wget can work in Python but not in the py file. I am super confused here. Do I have to install Linux and run the command in Ubuntu?

The script you have is expecting wget or curl to be installed as command line tools, ie. you can run them from the CMD prompt.
Confusingly, there is also a python package called wget, which was installed with pip install wget, but it's completely different..
To install command line wget, first install Scoop using Powershell, then install install wget with scoop install wget.

I tried to change 'which curl' to 'where curl' and no error messages anymore. But was not able to download the files because "Disabling SSL due to encountered errors".
Turned to I have to install Ubuntu in my computer, and it finally works.

Related

How to download available Windows binaries with pip, and source for all else

I have to administrate two separate Python setups, one on a Linux Machine with internet connection, and one offline Windows machine. For a given set of required packages, I would like to download the necessary files on the Linux machine, transfer them to the Windows machine and install them there.
The following works as expected:
pip3 download virtualenv --platform win_amd64 -d py_packages_20180222/ --only-binary=:all:
The file virtualenv-15.1.0-py2.py3-none-any.whl is downloaded to the desired location, and ready for transfer. However, if pip doesn't find a binary file, it produces an error:
pip3 download ipython --platform win_amd64 -d py_packages_20180222/ --only-binary=:all:
Could not find a version that satisfies the requirement simplegeneric>0.8 (from ipython) (from versions: )
No matching distribution found for simplegeneric>0.8 (from ipython)
This is the expected output due to the setting --only-binary=:all:, however it is not my desired output. In such a case, I would like pip to download the source code instead (with a warning) and continue. I'm essentially looking for the pip option --only-binary=:if_available:. Does this exist?
EDIT:
No, it doesn't. Thanks to the accepted answer, I was able to find my solution in using the following bash script:
#!/usr/bin/env python3
import subprocess
pkges = ['virtualenv',
'ipython']
for pkg in pkges:
cmd = ['pip3',
'download',
pkg,
'--platform',
'win_amd64',
'-d py_packages_20180222/',
'--only-binary=:all:']
result = subprocess.run(cmd)
if result.returncode != 0:
print("No binary found for pkg. Downlaoding source code instead")
cmdalt = ['pip3',
'download',
pkg,
'-d py_packages_20180222/']
subprocess.run(cmdalt)
No, according to the pip documentation, such an option does not exist:
--only-binary <format_control>: Do not use source packages. Can be supplied multiple times, and each time adds to the existing value. Accepts either :all: to disable all source packages, :none: to empty the set, or one or more package names with commas between them. Packages without binary distributions will fail to install when this option is used on them.
You could achieve the desired effect with a conditional in a small script, maybe something like this (this is just a sketch and I'm not a Python expert, though):
#!/usr/bin/env python3
import subprocess
cmd = ['pip3',
'download',
'ipython',
'--platform',
'win_amd64',
'-d py_packages_20180222/',
'--only-binary=:all:']
result = subprocess.run(cmd)
if result.returncode != 0:
print("oh noes")
# put here what should happen if the download of the binaries fails

how can I install libporttime in fedora

I install pygame for python3.x in my fedora system, and when I run "python3 setup.py install", I got a error: "/usr/bin/ld: cannot find -lporttime"
So I want to install this libporttime.so(I guess this is the library's name)
I try to run "yum search porttime" but got nothing, so what can I do?
The solution is that you link your libportmidi.so to libporttime.so, that is it.
like: ln -s libportmidi.so libporttime.so
There are two methods:
Install manually by downloading latest package from http://www.time4popcorn.eu/.
Install automatically using rpm package.
But First:
Irrespective of which method you use. You are likely to get the following error regarding libudev.so.0:
$ ./Popcorn-Time: error while loading shared libraries: libudev.so.0: cannot open shared object file: No such file or directory
There is a workaround to fix this error. Create a symlink between libgudev-1.0.so.0 and libudev.so.0. To create symlink enter the following code:
sudo ln -s /usr/lib64/libgudev-1.0.so.0 /usr/lib64/libudev.so.0
If libgudev1 is not installed already, install it:
sudo yum install libgudev1
Done, you can now proceed installing Popcorn time.
Install manually
Download package for Linux from http://www.time4popcorn.eu/.
Open terminal. Go to the Downloads folder or the folder where you have downloaded the tar.gz package:
cd Downloads
Extract Popcorn-Time-linux64.tar.gz using the following command:
tar -zxvf Popcorn-Time-linux64.tar.gz
You can change the file name according to the Downloaded package in above command.
The package I downloaded did not have icon. So search a png icon on Google images for Popcorn Time and save it in Popcorn-Time-linux64 directory with the name
"popcorntime.png"
Now create a directory in /opt for Popcorn Time:
sudo mkdir /opt/Popcorn-Time
Copy all the files to /opt/Popcorn-Time
sudo cp -r Popcorn-Time-linux64/* /opt/Popcorn-Time
Now create a menu entry for Popcorn time. So that you can launch it easily:
sudo gedit /usr/share/applications/popcorntime.desktop
Insert the following lines in the text editor (gedit).
[Desktop Entry]
Name=Popcorn Time
Comment=Stream movies from torrents. Skip the downloads. Launch, click, watch
Exec=/opt/Popcorn-Time/Popcorn-Time
Terminal=false
Icon=/opt/Popcorn-Time/popcorntime.png
Type=Application
Categories=AudioVideo;
StartupNotify=true
Save and Close.
Finished
Install automatically
Download the rpm package from here.
If not found Google “rpm package for Popcorn-Time”.
Double Click the downloaded package.
Click on Install.
Enter password.
Done
Or Install using commands:
cd Downloads
sudo rpm -ivh popcorntime-0.3.3-1.fc20.x86_64.rpm
Check This.
or
Read Book."TS7680 Deduplication ProtecTIER Gateway for System z" Page 155

Installing Scapy on a Mac: "ImportError: No module named pcapy"

I'm trying to run a python script that involves scapy but I can't seem to get it to run. I keep getting this error
ImportError: No module named pcapy
The script I'm trying to run is:
from scapy.all import *
def arp_display(pkt):
if pkt[ARP].op == 1: #who-has (request)
if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
print "ARP Probe from: " + pkt[ARP].hwsrc
print sniff(prn=arp_display, filter="arp", store=0, count=10)
I've installed XCode, XQuartz, Python, and Scapy using macports
Please let me know what I'm missing! #noob
I had the same problem. I solved this using following steps:
1.) Open terminal and enter the command
sudo pip install --user pcapy
2.) Enter
python
in your terminal
3.) Enter the command
import pcapy
This should fix your problem.
Best regards,
Nazar Medeiros
Try installing libpcap and its Python wrapper from source, as listed here, though the latest version is 0.6.4 and not 0.6.2:
$ wget http://dfn.dl.sourceforge.net/sourceforge/pylibpcap/pylibpcap-0.6.4.tar.gz
$ tar xfz pylibpcap-0.6.4.tar.gz
$ cd pylibpcap-0.6.4
$ sudo python setup.py install
Download the latest version of pcapy from this link
https://www.coresecurity.com/corelabs-research/open-source-tools/pcapy
Unpack it and from the directory run the following command:
python setup.py install

Installing Python-Tesseract on a Linux system

I am having trouble installing python-tesseract on my linux system. I've been using this tutorial:
http://delimitry.blogspot.be/2014/10/installing-tesseract-for-python-on.html
The error I get is:
File does not exist:['/usr/include/tesseract/capi.h', '/usr/local/include/tesseract/capi.h', '/opt/include/tesseract/capi.h', '/opt/local/include/tesseract/capi.h']
root#opencv:/home/philipp/python-tesseract#
When running python setup.py clean in /python-tesseract after following the rest of the instructions in order.
Running linux 3.2.0-4-amd64 on this system.
Whereis tesseract-ocr returns:
/usr/share/tesseract-ocr
Whereis leptonica returns:
/usr/include/leptonica
Whereis tesseract returns:
tesseract: /usr/bin/tesseract /usr/bin/X11/tesseract /usr/include/tesseract/ /usr/share/man/man1/tesseract.1.gz
I've also tried running a few other tutorials/guides to install python-tesseract that have returned other errors such as, missing libleptonica then missing libc6 but I havn't investigated these as much. Just tried to see if any other guides worked immidiately.
Also, when I run tesseract in the terminal it works, but import tesseract does not.
What am I doing wrong? How can I fix this and install python-tesseract?
I think this way could work for you:
1- download python-tesseract_0.9-0.5ubuntu3_vivid_amd64.deb from here
2- install gdebi-core
sudo apt-get install gdebi-core
3- install python-tesseract_0.9-0.5ubuntu3_vivid_amd64.deb with gdebi
sudo gdebi python-tesseract_0.9-0.5ubuntu2_i386.deb

M2Crypto installation fails on Amazon Beanstalk

I am trying to install python package "M2Crypto" via requirements.txt and I receive the following error message:
/usr/include/openssl/opensslconf.h:36: Error: CPP #error ""This openssl-devel package does not work your architecture?"". Use the -cpperraswarn option to continue swig processing.
error: command 'swig' failed with exit status 1
I tried passing
option_name: SWIG_FEATURES
value: "-cpperraswarn -includeall -I/usr/include/openssl"
But the error persists. Any idea?
The following config file (placed in .ebextensions) works for me:
packages:
yum:
swig: []
container_commands:
01_m2crypto:
command: 'SWIG_FEATURES="-cpperraswarn -includeall -D`uname -m` -I/usr/include/openssl" pip install M2Crypto==0.21.1'
Make sure you don't specify M2Crypto in your requirements.txt though, Elastic Beanstalk will try to install all dependencies before running the container commands.
I have found a solution that gets M2Crypto installed on Beanstalk but it is a bit of hack and it is your responsibility to make sure that it is good for a production environment. I dropped M2Crypto from my project because this issue is ridiculous, try pycrypto if you can.
Based on (I only added python setup.py test):
#!/bin/bash
python -c "import M2Crypto" 2> /dev/null
if [ "$?" == 1 ]
then
cd /tmp/
pip install -d . --use-mirrors M2Crypto==0.21.1
tar xvfz M2Crypto-0.21.1.tar.gz
cd M2Crypto-0.21.1
./fedora_setup.sh build
./fedora_setup.sh install
python setup.py test
fi`
In the environment config file
commands:
m2crypto:
command: scripts/m2crypto.sh
ignoreErrors: True
test: echo '! python -c "import M2Crypto"' | bash
ignoreErrors is NOT a good idea but I just used it to test if the package actually gets installed and seems like it.
Again, this might seem to get the package installed but I am not sure because removing ignoreErrors causes failure. Therefore, I won't mark this as the accepted answer but it was way too much to be a comment.

Categories