I have a python code which I need to send it to a client who will run it windows.
The python code works on a few imported modules mentioned in requirements.txt:
requests==2.11.1
xlwt==1.1.2
beautifulsoup4==4.5.1
If I have to execute the code in windows, I’ll have manually ask the client to download these above modules before running the script.
I have created a bash script ( for linux), which is such:
sudo pip install -r requirements.txt
echo "Requirements met"
python ./isb.py
What is the bash script equivalent in windows? I want to client to only execute 1 file which executes other remaining files.
Can an executable be made for a task like this?
The code and other files are here if need be.
I has similar task in the past. So I just used a tool py2exe which builds a standalone executable and it resolves dependencies at build time. A valid python interpreter will be included to the build. So your client can just execute this standalone exe file by double-click or from cmd shell.
Related
I have to run a shell script on a Centos Linux machine that calls a python file. Inside the python file, there is the following code snippet:
from lib.rclone import Rclone
rclone = Rclone()
if shutil.which("rclone") == None:
print("Rclone executable is missing, install it")`
The problem is that I am not supposed to install any code (including rclone) on the machine. Therefore, whenever I call the shell script, it ends up with the error message. I don't know how can I successfully run it?
The program you are running requires rclone. Since you cannot install it, you cannot run it. Simple as that.
You can try to release the script as a .exe file.
By using pyinstaller (https://pyinstaller.org/) you don't have to install any libs or py package on the target machine, you can even choose to release it as a single executable.
I had made more than 1 pytest test files I needed it to be convert them to a single exe file
I used pyinstaller for that not able to convert the test cases to .exe file
Even though if some how I will convert it I could not run it via clicking on .exe file as on console I am running it by python -m pytest
So Please help me guys
Create a bat file rather, if you want to run it on a windows environment.
Keep the required libraries ( like pytest, selenium.. etc) in a requirements.txt file in root directory.
Keep the bat file with the root directory.
The commands in the bat file will go as below.
cd path/to/current/directory &
virtualenv env &
"cmd.exe" "\c .env/Scripts/Activte && pip install -r
requirements.txt && pytes your commands to trigger script
here"
Once you hit the bat the dependent Libraries will be installed and later your scripts will trigger
Is there any way to execute the exe file created by pyinstaller, that like on just clicking the exe file the exe will get execute based on the code mentioned just like on clicking the exe file the code should execute via python -m pytest
I have this file.py:
import os
os.system("pip install pip")
os.system("pip install selenium")
How do I make it work for MAC and what is te equivallent of a .bat file in MAC to execute the file.py.
Your file.py script will generally work fine on Mac as long as the environment the script is running in is set up right. Most notably, the pip executable has to be findable via the current PATH variable. You might benefit by looking at the subprocess module, which is an alternative API for running external commands. It is a more robust mechanism for doing so.
The equivalent of a .BAT file is a shell script. You have a choice as to which shell to use to run the script. I think the most common source is the Bash shell. It is often the case that you use whatever shell is running at your command prompt. This functionality is generally much more general and flexible than a .BAT file is on Window. See this link for a discussion of many of the issues:
https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/shell_scripts/shell_scripts.html
A shell script can just be one or more commands that you might run in your Terminal. For example, to run test.py at a Terminal prompt, you'd do this:
> python test.py
The simplest equivalent in a shell script would be the same thing:
python test.py
A script that looks like this is run by whatever shell executes the shell script. What is more usually done is that a "shebang" line is added to the top of the shell script to explicitly define which shell will be used to run the script. So what the single line script above should really look like is this:
#!/bin/sh
python test.py
This may be starting to make your head spin. I would suggest reviewing the link I gave above, and possibly reviewing some other materials that explain shell scripts. Note that nothing about shell scripts is unique to the Mac. The concept is exactly the same on Linux, Unix, etc.
BTW, do you really want pip install pip? What does that do? Doesn't the pip package have to already be installed if the pip command is working?
I am trying to run Jmeter tests with the help of taurus in jenkins with performance plugin. In my yml file I have passed the scenarios to run jmx scripts and in jenkins I am using execute shell to run my tests
bzt test_suite.yml -report
I have also set the current directory as my workspace in jenkins. So, when I build the project in build console I get the following output
Running as SYSTEM
Building in workspace C:\Users\muhammad.taus\PycharmProjects\PerfAutomationFramework
[PerfAutomationFramework] $ sh -xe C:\Users\MUHAMM~1.TAU\AppData\Local\Temp\jenkins2737910596558040446.sh
+ bzt test_suite.yml -report
C:\Users\MUHAMM~1.TAU\AppData\Local\Temp\jenkins2737910596558040446.sh: line 2: bzt: command not found
Build step 'Execute shell' marked build as failure
Creating parser with percentiles:'0,50,90,100,' filterRegex:
Cannot detect file type because of error: Failed to copy C:\Users\muhammad.taus\PycharmProjects\PerfAutomationFramework\stats.xml to C:\Users\muhammad.taus\.jenkins\jobs\PerformanceAutomation\builds\36\temp\stats.xml
Finished: FAILURE
But previously the tests used to run fine on my host. I installed taurus using pip and in CMD When I type bzt it gets taurus, also when I type py it picks python and also I have setup JMETER_HOME and in cmd when I used jmeter it opens Jmeter. I am not sure what happened but I am not able to execute the tests anymore. The only thing I remember is changing python version from 32 bit to 64 bit, But I am sure that is not causing the problem. Please if anyone can help me in this regard it would be great.
You have some weird mix of Linux and Windows and your question doesn't contain sufficient level of details in order to troubleshoot the issue.
Use the full path to python executable in your shell script
Instead of bzt use /path/to/python -m bzt.cli your_config.yml
If you get No module named bzt install it using pip:
python -m pip install bzt
If python executable is not found, try python3 instead
More information:
Installing and Upgrading Taurus
Integrating Taurus with Jenkins
How to Run Taurus with the Jenkins Performance Plugin
I'm using: Python 2.7 and Pyinstaller 2.1.
I'm able to successfully create a single executable with the -F argument. My script leverages wget to upload a file to a remote server. Let's just say that I need to use either wget or curl to achieve this (I know there are other modules that can accomplish this). This is done via a subprocess call. The problem that I'm having is that whatever Windows machine executes the script, wget/curl must already be installed.
Is there a way, via Pyinstaller, to include the wget binaries? So that the executable contains all the necessities to run the script and utilize wget/curl?
Thank you in advance.