I want to run a python script on a Linux Box(I'm connecting to it through SSH on OSX terminal). In order for this script to run, the computer must have the SUDS module installed. I was wondering what would be the best way to install SUDS on computers that run my script and do not have SUDS installed in them. My script is in a folder the has a virtual env. The structure of my folder is:
MainFolder
-------script.py, env folder
|----------binFolder, includeFolder, libFolder
Should I code my script to install SUDS from the script itself?Or is there a better method to achieve this?
Also, I would like to know if there's a way to run my virtualenv through the SSH and use pip to install in the Linux Box?
Well it depends if you are deploying it only on this server and do not want to distribute the code than you would have to run the following command (assuming you have pip and python-tools)
sudo pip install SUDS
but if you get an error back saying that the command pip is not installed you will need to run the following command
sudo apt-get install python-pip python-dev build-essential
If you want to distribute it than I would do open source on github
with the instructions of how to use the program and run it I would add a dependencies list of all the external modules you used for your script.
Hope this helped.
Related
I am doing coursework and one of the important requirements is to create a .bat file for scripts. The bat file should run the script. I took this step until one thought struck me.
Code .bat file:
#echo off
py -u "Task_1.py"
echo %ERRORLEVEL%
pause
In my code, I use many third-party libraries, including for creating an interface. Let's assume that this script will run on a computer without python. Is it possible to somehow write a .bat file that would check for the presence of python and third-party libraries, and in their absence would download them? Has anyone done something similar, could you suggest how this can be implemented?
You could have the .bat file run a python environment you make and pip install dependencies, would be worth looking into.
This answer says that curl comes with Windows version 10 or newer. Therefore I would just curl the installer:
curl https://www.python.org/ftp/python/3.10.1/python-3.10.1-amd64.exe
now run it with /quit as by this answer:
.\python-3.10.1-amd64.exe /quiet
Then you can install pip as suggested as an alternative method from the official pip website:
py -m pip install --upgrade pip
Now you can use pip install to get whatever libraries you might need:
pip install numpy
Note: I have not been able to test this on my Windows so use with caution
In your .bat script, you can first run py --version and check the return code of the command to see if Windows could find py.
If it couldn't:
Download a Python installer. I don't know which utility is supposed to do that on Windows, but it should look similar to this (wget on Linux, saves the installer as python-installer.exe):
wget -O python-installer.exe https://www.python.org/ftp/python/3.10.1/python-3.10.1-amd64.exe
Then launch it and let the user go through the installation:
./python-installer.exe
Then, execute pip install --user your libs to install the libaries if needed.
Then, run your Python script.
I found a post to check if python is installed or not (How do I test if Python is installed on Windows (10), and run an exe to install it if its not installed?). It explains it quite well.
For the modules I would suggest using pip and installing the required modules by a requirements file.
I have multiple issue
First issue:
I have a server which is so secure that is running
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.4
There is no internet connectivity there and I want to download some packages like
pysnmp
pandas
numpy
psutil
some others
As per my research, the best way to download from server that has internet and transfer the file to the server that does not have an internet.
I tried of things, like download tar.gz of the package or use basket or take full package but no use
Second issue:
While I am trying, I am getting No module named pkg_resources error.Hhow can I solve that first in-order to proceed?
my python version is
python2 is 2.7.5
python3 is 3.4.9
i am tried pip install pysnmp-4.4.12.tar.gz to the main package. it mention to be no Module pk_resource.
i tried also to use basket as per the website https://pythonhosted.org/Basket/
and i used easy_install -f ~/.basket -H None pyramid
and i got pkg_resource module error.
However When i download setuptools through the website https://pypi.org/project/setuptools/0.9.8/#installation-instructions
and i use python eazy-setup.py --user the Error is
[Errno 13] Permission denied: '/usr/lib64/python2.7/site-packages/XlsxWriter-1.1.2.dist-info'
Updated !!!!
I managed to do it Thanks for the help
I the problem is dependency tree i suggest running a local pip server : https://pypi.org/project/pypiserver/
and copy all needed package to server you can see it with:
pip freeze
and install your package with:
pip install --extra-index-url http://localhost:8080/simple/
so Here is the solution!!
For this problem:
No module named pkg_resources error
i was using pip install pysnmp or pip install pandas
i should use python -m pip install
the second issue :
the Error is [Errno 13] Permission denied: '/usr/lib64/python2.7/site-packages/XlsxWriter-1.1.2.dist-info'
the solution is sudo python -m pip install
The main reasons is that secured Server is used to have multiple users ( Main user where main function is running)
so using sudo is important
Finally how to install package is easy.
Go to pypi and download
pandas-0.25.3-cp36-cp36m-manylinux1_x86_64.whl
then sudo python3 -m pip install pandas-0.25.3-cp36-cp36-manylinux1_x86_64.whl
some Tips:
try to use virtual machine like virtual box for testing how to install and once it is install try to browser for it. Why i am saying that because i am running Windows and my server is Redhat so any solution on my windows is useless so i had to use my laptop with virtual box ( I cant download Virtual box due security)
second thing, python is different than python3 so if you use python in your virtual box which is host Linux server , you will get pandas-0.25.3-cp27-cp27-manylinux1_x86_64.whl not pandas-0.25.3-cp36-cp36-manylinux1_x86_64.whl so becareful
and Last tip once you done use sudo python whateveryouwant torun.py
again why sudo because all of your packages are inside main file not inside your user
Hope i managed to answer my self correctly
I am facing problems installing pyobjc on my mac.
Basically I have to install pyobjc on a new Mac System in the system default python. I have so far tried easy_install, pip and downloading the pkg file and installing. All give me a error in different ways. Some give me a error saying certain safari files are missing other cant due to some permission being denied even though I am running them through sudo su.
I then found a fix.
pip install pyobjc --user
This worked and I could access all the modules I required, but then if I try running python through sudo, I cant access those modules.
Can anyone suggest a fix for this.
NOTE: I don't mind a different method to install also. Also I have not tried brew due to some previous difficulties with it.
NOTE 2: I need to be able to access those modules using all users on the computer, the root user and me(the non-root user)
i had to (temporarily) move (using sudo) /Library/Python/2.7/site-packages/Extras.pth to another name before I could install the current pyobjc.
This is what works for me:
sudo mv /Library/Python/2.7/site-packages/Extras.pth /Library/Python/2.7/site-packages/Extras.pth_orig
pip install --upgrade pyobjc
sudo mv /Library/Python/2.7/site-packages/Extras.pth_orig /Library/Python/2.7/site-packages/Extras.pth
It appears that something in the .pth file interferes with the install, but does not impede running pyobjc.
but then if I try running python through sudo, I cant access those
modules.
Because sudo python basically means run python as some other user (root by default). That user may have a different set of environment variables, including $PATH.
Some of linux distributions use older Python version for root user,like centos.If the Python verison you're running with sudo isn't correct,you can't access those modules installed by pip.
So in my opinion,if you didn't get permission issues,you don't need to use sudo ,using sudo might bring unexpected mistakes(most environment variables issues),maybe chown or chmod can fix those issues.
So here are my plans:
Plan A: The best way is to try to use virtualenv.
Plan B: Install modules without sudo command,if got permission errors(not very common),try --user .
Install to the Python user install directory for your platform.
Typically ~/.local/, or %APPDATA%Python on Windows.
In most cases,you should modify your PYTHONPATH.See details from How do I access packages installed by pip --user.
Plan C: All related commands are executed with sudo.sudo pip install (all modules) and sudo python script.py.Not a good idea.
I am new to TeamCity and I do not know how to install packages I have imported in my python code on the TeamCity server. For example I have imported selenium in my code and tried to install it using command line on TeamCity by pip install selenium but I got the error pip: command not found. I am not sure this is the best way to install needed packages.
It seems like you don't have "pip" (Python package manager) installed on the machine that your Team City agent is running on. Team City does nothing but triggering your builds. In your case, it probably is only resolving dependencies (your Python packages) and running your code.
So you need to install pip on the machine that is running the Team City agent. (You might have multiple agents, install pip on all agents that might build this python project)
You might want to upgrade your Python. Python 2.7.9 and later already comes with pip. https://www.python.org/downloads/
Instruction on how to install pip.
https://pip.pypa.io/en/latest/installing.html
You can SSH to that machine and run the following bash script (assuming you are on UNIX).
$ curl https://bootstrap.pypa.io/get-pip.py >> get-pip.py && sudo python get-pip.py
I wrote a python program on Ubuntu(machine 1), working well.
I want to make it executable on machine 2(Fresh Ubuntu Installed) by using cxfreeze.
I run following commands on machine 2 terminal
sudo apt-get install python-pip
sudo pip install cxfreeze
cxfreeze pythonfile.py
After these command, when I try to run executable file, its Not working.
Not Working: means no error, no action and no message
It is my first experience, so want to know what steps I have to take before make it executable on different Ubuntu machine.