Automatically install libraries - python

Even if i risk some negative votes, i want to ask you about a strategy to do some automaticaaly installations of libraries and packages. I tested and worked great the strategy of finding all libraries from pip freeze and attaching them into a file.txt . After that, i used pip install -r file.txt. So far,so good. But what cand you do when you want to gradually add libraries and don't want to write manually in the file.txt,but simply have a code that reads the new library,eventually use the subprocess and installs it automatically? The purpose behind this question is to make the code to work at its fullest only when compiling the program (one single human action,when you run the code, it reads the new libraries and installs it automatically,without to write them in the file.txt) . Any ideas are apreciated,thank you!:)

It seems like you already have all of the parts in place. Why not just write a bash script that runs every day to call pip freeze, put it in the txt file, and update everything?
Then run the script as often as you want with crontab

Related

Using local modules Python without installation

I need to pack an application written in Python.
I can't use PyInstaller because I can't have a .exe or anything like that, I need pure python scripts being executed (I have Popen in my code calling some of my scripts and passing parameters);
I need it to work cross-plataform (I KNOW that to do so, I need to generate the package in each system because a package generated on Linux won't work in a Mac and vice-versa);
Since I can't really pack it, my idea is to have a folder called modules and have all the dependencies inside it, then, in my code I would just point the imports to this folder. I would zip the entire project and ship it, the user would just unpack and run it.
The problem is:
How to not only download the package in a specific folder but also install it there? (I can't alter my user's environment, this is a MUST);
How to direct my imports to this local folder? I think I can do something like import modules.numpy for example, but then, numpy have dependencies of its own... how to make sure it will look into my custom folder?
My scenario:
I have a requirements.txt for my project; I have several local files that are used inside the project; I have a Popen that calls one of my file.py; I am using Python3;
I can't use virtualenv because I am using wxPython and there's a conflict between it and virtualenv (no idea why - something related with main thread...)

How do i install a python script like package manager does?

If i try to install a package from package manager in any kind of Linux based system, it is installed, adds a shortcut to system menu and so on. It removes the whole package if i type:
"sudo apt autoremove 'packagename'"
How can i do that kind of stuff for my own python script? How is it possible to create a shortcut and install the script for my own system? So i can quickly access it from system menu and uninstall it with one command as i want? I dont want to add a shortcut manually or dont want to distribute my program in a repository, just want it to act like a regular packaged program.
The "package" contains dozens of small distro-specific configuration snippets and scripts to integrate the packaged program with the rest of the system. Some parts of this are specified in distro-neutral standards such as http://freedesktop.org/ but the most accessible documentation will probably be in the packaging manual for your particular distro. For Debian and derivatives (Mint, Ubuntu, etc) the authoritative documentation will be the Debian Developers' Reference, but you might want to start with the Debian Wiki "Packaging" page.
For your specific question about creating a menu entry or a desktop shortcut, you want a .desktop file.
Creating a .deb file for a simple Python scipt and a .desktop file for it is eventually a fairly simple task, but getting a grasp of the entire stack from Python packaging basics to distributing it from a simple PPA or local file system is probably going to take some effort. If you already have a correct setup.py file, the next step would probably be to wrap it with a simple debhelper package, then add a .desktop file once you have that working.
If you're using linux just use aliases . That is the easiest way . alias aliasname='commands'
#!/usr/bin/python
import os
def alias_writer(bashrc, a_name, a_command):
with open(bashrc, 'a') as bash_profile:
bash_profile.write('alias ' + a_name+'='+a_command+'\n')
os.system("source " + bashrc)
alias_writer('/Users/user/.bash_profile', 'runpy', 'python')
That write a alias 'runpy' and runs the python console. In terminal you would write 'runpy'. Also add a alias for this file to create a alias :)

Proper way to change bashrc when making a ubuntu package or python package

I'm planning to make a program which should edit the users bashrc.
In the case of python library, I'd like to add a binary to /bin/ automatically. When it is executed, then it should add a function and call it every time when a user is loggd in to bash, so I definitely should change bashrc.
In the case of ubuntu package, it should do same job as desribed above.
However, adding some function to bashrc seems not a proper solution because when it is removed, it should edit bashrc again but if there is any small change of added codes removal of package might make some dummy codes on bashrc.
Is there any neet solution for this?
assuming ubuntu is somewhat like debian.
/etc/profile.d is probably the best way.
Don't edit any files just drop a file into profile.d that checks for bash and that your package is installed and then does whatever it needs.

iexpress assistance for my program

ok so i've used iexpress a few times without a problem. i created a nice little program for my buddies and i and i'm now in the process of creating a installation package for it. i like iexpress cause it makes it easy and has the license agreement window n whatnot.
ok so program is made. using windows & iexpress i attempt to make the installer, problem is there is one folder that contains an item i need and it needs to be in that folder directory when the installed program needs to run. Problem: i can select files but not folders for the list of items to be in the installer.
Question: how do i include the folder in the install package so there doesnt need to be a few more additional steps for the installation.
i have thought about zipping it, but there isnt a way (that i know of) to add a extract command after the initial install extract.
i figure installers are to programs what instruction booklets are to Ikea furniture so i figured this would be the best place for help. tyvm
iexpress doesn't let you include folders, but you can include a batch file, which may create folders and copy files to the respective folder. To run a batch file, specify cmd /c IncludedBatchFile.bat under Install Program in the iexpress wizard.

What scripts would go into a bin folder of a Python package?

I'm learning about Python Packages from Learn Python the Hard Way and one of the exercises it says:
Put a script in the bin directory that you can run
To me, it seems kind of vague. I'm not exactly sure what kind of scripts would go into the bin folder. The Hitchhiker's Guide to Packaging says
put into bin any scripts you’ve written that use your package and which you think would be useful for your users. If you don’t have any, then remove the bin directory.
But I'm still left wondering what kind of script would go in there. So, I know its may sound like a dumb question, but can someone give me an example of when, and why one would put "a script" in their package's bin folder?
I just recently got through Ex46 in LPTHW myself. Like you, I was confused by the scripts. In case the other answer was too advanced for you, I ended up just putting in a simple "hello world" script:
#!/usr/bin/env python
from test3 import printstring
printstring.printstring("test script working")
print "test over"
I named that file testscript3.py (*Note, I learned later that it would be more convenient to leave off the .py filename extension if it were a real script that I wanted to seem like a system command)
My file test3.py was like so:
def printstring(s='you did not provide string'):
print s
Here's some newbie things that I learned while trying to get this process to work:
The #! symbol is sometimes pronounced shebang and the simple explanation is that the command on that line tells the shell to use python to run the script. If you leave off the ".py" filename extension, then the user of the script doesn't need to care what interpreter is needed to run the script. See wikipedia shebang article.
I ran the following command to package the distribution:
python setup.py sdist
After doing that, I was able to install the package and script by running
sudo pip install test3-0.1.tar.gz
One thing I worried about was permissions on the script file. However, I noticed that distutils took care of this when packaging (changed mode to 755 or whatever).
You can find my whole project for this example on github.
For example Django's project creating, Scrapy's project creating, django-admin.py and scrapy are both scripts in bin folder.
You could get even more examples by checking almost python-based tools.

Categories