I was wondering if the following is possible.
I have a BASH script that I want to make available for some people but I wanted them to only have to "install" the program and not messing around with terminal, so I thought a .deb would be cool.
So what would the "install" do?
Simple. I want to move the script and an icon to a folder (any folder, but I was wondering some hidden folder in Home) and then run a script that creates a launcher in the Applications menu for the first script. It seems there isn't much to it, but for what I've searched, there doesn't seem to be a lot of info...
How can I accomplish this?
By the way, I'm using Ubuntu 11.04.
Basically (install and) run dh-make to set up the debian/ directory, edit the generated files (mainly remove the many you do not need, and fill in a package description and any dependencies in debian/control), then debuild-us -uc -b.
You may also have to set up a simple Makefile for debian/rules to call; it probably only needs an install target to copy the binary to $(DESTDIR)/usr/bin.
Binaries install into /usr/bin and you should not try to override that. The way to have a menu is to add a .desktop file.
Once you have a good .deb you will need to set up a repo for distributing it. The simplest solution is probably to set up a launchpad.net account and create a personal PPA there.
It's not hard to find more information on these topics, but of course, you need to know what to look for. The canonical documentation is the Debian New Maintainer's Guide.
Found this video on youtube that explains IN FULL the process of creating a *.deb for a script or program and even mentions how to do it for a C program.
Full guide in how to build simple *.deb package
Has one bug, btw, that the author, during the making of the *.deb, didn't notice. The path in the *.desktop file for the EXEC parameter is wrong in the example.
Related
I am totally new to Julia!
I would like to install a large number of packages for a project I'm joining.
The project comes with a "Project.toml" file
It seems like there should be a nice way to install all the packages I need for the project, perhaps using the Project.toml file
However, I have not yet found any site that indicates how I might be able to do this.
Could anyone please let me know if what I am doing is possible, and if so, point me to a reference that would show how?
If your Project.toml is located in a folder, like myproject/Project.toml, you can simply start Julia with julia --project=/path/to/myproject, and it will automatically detect the Project.toml file in myproject.
The first time you activate this project, in the REPL, you can switch to Pkg mode by typing ], and type the command instantiate. This will cause the package manager to download and install all of the packages listed in Project.toml and their dependencies.
Another way to switch between projects during interactive use is to run activate /path/to/myproject in Pkg-mode in the REPL.
How to install julia packages from a Project.toml
First, you will have navigate to the folder containing your Project.toml.
cd ../your-folder-containing-the-project.toml-file
in your terminal:
julia --project=.
]
instantiate
or
julia --project=. -e 'using Pkg; Pkg.instantiate()
The other answers went already to the point, but I want to add another important aspect.
If this project comes "only" with a Project.toml file, you will be able to install "sone version" of these packages, eventualy the Project.toml may also give you a range of versions known to work with the project you have been given.
But if this project comes also with a Manifest.toml file you will be able to recreate on your pc the exact environment, will all the exact versions of all dependent packages recursivelly, of the guy that passed you the project, using the ways desctibed in detail in the other answers (e.g. ] activate [folder]; instantiate).
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
I decided recently that I want to start learning to code. I chose python as my first language because of it's versatility and Open Source connections. Now, of course to learn any programming language, first you have to be able to practice with it by writing code and running it.
I have Python beginner tutorials I am using but as soon as I got to the point where I wanted to run a simple Hello World message, I couldn't figure out how to get my document to actually RUN. I downloaded LiClipse with the hopes of using PyDev. I read that you can run a code directly from PyDev.
Wow, what a confusing mess! I downloaded the instant install version of LiClipse and I had to manually update the pip because it was out of date and that took an hour of research all on it's own to figure out how to do it.
Now that I have the interpreter set up correctly with the most recent pip...(I THINK), when I try to run any code I write, it doesn't let me. It wants me to save it first, which of course is quite logical. But when I try to save it, it says there is no folders to save to. How can there be no folders? I have been reading the install help, but it doesn't say anything about this issue. Or maybe it did explain how to fix this issue and I simply didn't understand all the jargon included in the configuration documentation. It kept instructing me to do technical things I couldn't understand.
Can anyone tell me what is going on? Shouldn't this all be ready to go when I used the "instant install" ?? I am just a beginner here, I don't know all this technical installation jargon. If anyone can help me get this setup, please let me know.
I really want to start learning. But I can't if I don't have the right tools.
Yeah, the technical jargon can be really confusing in the beginning. I've never heard of LiClipse but I can give you a few tips to get started:
Use a good IDE or Editor. For beginning VsCode with the Python PlugIn is quite good. You can also use PyCharm (the free version is enough) but that IDE is quite confusing.
Get comfortable with the commandline. On Windows you can invoke Python by running py on Linux with python3. You open the commandline on Windows by opening the startmenu, entering cmd and hitting enter.
You will have to make sure Python is in your "PATH" enviroment variable. That is a variable telling the Operating System where to find your programms. It should have asked you whether you want to add Python to your PATH during the install.
You run your python programm by saving it as a .py file and running py <filename.py> or python3 <filename.py> on Windows or linux respectively. You have to be in the directory where you saved your file of course.
I hope I could help you. Please mark this answer as accepted if it did answer your question or helped you with your issue.
I want to start by saying I'm mainly experienced in C & C++, not Python, but with programming in general many of the concepts carry over. I also don't have enough rep to comment, or I'd ask for some clarification on how familiar you are with the commandline.
I'm going to assume you're on Windows since you didn't mention the platform.
I wrote this like a tutorial, because I found those to be very helpful when I first started programming.
I can't recommend this enough, start off by using the commandline!
I think you complicated things more by searching for a text editor that can also run code. In order to get something like that working for your setup you need to know what's happening behind-the-scenes first.
Once you have a grasp of how to write & execute Python code, then you can move on to an IDE or advanced text editor like Visual Studio Code or LiClipse with confidence.
R+Click on the Start Menu, then click on Windows PowerShell to open a terminal.
Take a moment to note the filepath shown before the blinking cursor.
This is known as the Working Directory, which works similar to how the file explorer only allows you to "view" one directory at any given time; You can open multiple explorer windows side-by-side, but you can't view multiple directories at the same time in a single window.
You can run commands by typing them and pressing Enter.
You can also use the Tab key to autocomplete things like directory/file names, commands, etc. after typing a few characters.
Now let's create a workspace directory for your first project.
This can be anywhere that you choose, but for the sake of simplicity I'll be using my User directory which is usually where PowerShell will start by default.
To create a new directory named _workspace, use the mkdir (Make Directory) command like so:
mkdir _workspace
Now let's change our working directory to _workspace by using the cd (Change Directory) command like so:
cd _workspace
This directory is empty, but if you want to view the contents of a directory you can use the ls (List Directory) command:
ls
Since this is an empty directory, nothing will happen.
Next, we'll create a Python script file using the touch command, which creates empty files:
touch HelloWorld.py
Now that we have a script file, open HelloWorld.py in Notepad by running this command:
notepad HelloWorld.py
If you use a dark desktop theme, now is the time when your retinas may be seared out by the intensity of Notepad's white color scheme.
Now, let's add the code to print "Hello World!" in Python:
print("Hello World!")
Once you're done, you can save & close Notepad to save your retinas.
Now it's time to run the program! In the PowerShell window, enter this command:
py HelloWorld.py
which will show:
Hello World!
If you see an error saying this:
The term 'py' is not recognized as the name of a cmdlet, function, script file, or operable program.
You should re-install Python and make sure you check this box in the installer:
After re-installing Python and checking the Add to PATH box, close and reopen the PowerShell window, enter the cd _workspace command again, followed by py HelloWorld.py, which should be successful this time.
I hope I could be of some help, if so, I'd greatly appreciate marking this answer as accepted so I can write comments. Happy coding!
If you are using Linux following will work.
Install python3 first (Its better to stuck on python3 now. Once you get use-to then you can code in python2.7 also.)
Open a terminal, go the folder contains your code. If your source code is in hello.py then type python3 hello.py on terminal. It will execute and print the output on terminal.
The suggestions given by both #radj and #C. Dautermann are excellent.
Like others here, I will be assuming that you are on Windows.
Before jumping into LiClipse and PyDev, I highly recommend making sure that Python and packages (such as pip) are functioning on their own first. Command line is a great tool for this.
Windows Command Line can be accessed in a variety of ways, one of which is to go to your start menu and search "cmd." Command Prompt should return. In the command prompt, run the following:
python
This should return the version of Python installed on your machine if it is configured properly. For example, you may see the following:
Python 3.10.1 (...)[...] on win32
If this does not appear, I recommend uninstalling Python and reinstalling. In the installer, you will want to check the "Add Python ... to PATH" option. This will configure your environment variables on your machine. If you plan on running multiple versions of Python down the road, don't worry; you can use batch files to set the PATH variable to another version.
Once you have Python working, your command prompt will lead with the following:
>>>
Notice that there is no longer a file path followed by >>. This is because you are now in the Python interpreter. Congratulations!
To exit the Python interpreter, enter Ctrl+Z. It should appear as the following:
^Z
After we know Python works, we will check to see that pip works. Ensure you have pip installed by entering the following:
python -m pip --version
You should then be able to see the pip version. For example:
pip 22.0.3 from C:\...
If pip is not working, you can consult this documentation on pip to make sure pip gets installed properly.
Once pip is working, again, congratulations! You've gotten over some of the biggest hurdles. At this point, you can open up any text editor, type in:
print('Hello World!')
save the file with the extension .py, then run the script through command prompt. To run a script through the command line, you have to cd to the file location, then run the script with python, like so:
cd filepath
python filename.py
Where filepath is the path to the Python file and filename is the name of the file. For example:
cd C:\Users\name\Documents\PythonPractice
python helloworld.py
Usually, command line is all that is needed when starting out with Python outside of a text editor. Notepad comes standard on Windows computers, but there are plenty of other editors out there. Sublime text and Notepad++ are some of my favorites, personally.
Now, if you're able to run everything prior, the good news is that your Python and pip are both working, and you have everything you need to get started learning Python. If Python and/or pip are not functioning, there's thankfully a huge body of troubleshooting tips out there.
Unfortunately, from what I get of your initial post, you might be struggling with configuring LiClipse. I personally do not use LiClipse, nor do I use PyDev, so my help at this point may be limited. You may want to uninstall and reinstall after confirming your Python and pip work as a first step. After that, perhaps check that you are following the practices outlined in the LiClipse manual. Worst case scenario, you can try a different version of Python (I believe it has some Python3 incompatibilities), try running PyDev independent of LiClipse, or look at a different tool. If you believe the problem lies with file locations/existence, I would look at radj's post or play around in File Explorer to see what is going on for yourself.
Again, to get familiar with Python, you don't even need these extra tools. All you need is a text editor and the command line to get started.
Some other tools to help you get started:
PyPI
A venv virtual environment tutorial
PyDev
A comparison of LiClipse alternatives in case you continue to struggle
Hope this helps. Happy Coding!
pyenv-virtualenv offers a nice way of activating the environment on the very instant of entering or leaving the directory which contains a .python-version text file which specifies the environment to activate. It works for the directory it is in and all directories contained in it.
The environment is deactivated once we change the directory to something above it. This allows to easily switch between projects or analyses using different python versions (just by changing the directories).
Is there a way of achieving the same behaviour with (ana)conda?
Edit: added bash tag, because - as far as I understand - pyenv achieves this by hooking a custom script into .bashrc (which allows it to monitor the directory changes). If there is no build-in way in conda, how to create a script which would make it possible?
As mentioned in my comment, this is currently not supported. There is however an open issue on conda's GitHub asking for this feature.
In the meantime you could use autoenv, a small tool that'll automatically run the code in a .env file when entering a directory and that in a .env.leave when leaving the directory (supports bash/zsh and a couple others).
A simple example taken from their readme which illustrates the feature quite nicely:
$ echo "echo 'whoa'" > project/.env
$ cd project
whoa
To load a conda environment your .env would simply look like this:
conda activate <my_env>
Note 1: Check out the Configuration section of their GitHub readme before you start using it.
Note 2: The author of autoenv actually suggests trying direnv instead. However I've never used it, so I can't comment on it.
From autoenv's readme:
you should probably use direnv instead. Simply put, it is higher quality software. But, autoenv is still great, too. Maybe try both? :)
Good morning, I am reading about the prepared scripts in MacOSX to use when creating a pkg for my application.
In particular, I have some doubts how to make sure that postupgrade script is used.
What I read till now is:
from here
The postupgrade script is run after files have been installed and before the postflight script if one is defined. This script is run only if the component has been previously installed. If the script does not return an exit status of zero, Installer will declare the installation has failed.
Ok then it seems that postupgrade will just run in automatic when an upgrade is done. BUT...from man pkgbuild, section --scripts scripts-path
Archive the entire contents of scripts-path as the package scripts. If this directory contains scripts named preinstall and/or postinstall, these will be run as the top-level scripts of the package. If you want to run scripts for specific bundles, you must specify those in a component property list; see more at COMPONENT PROPERTY LIST. Any other files under scripts-path will be used only if the top-level or component-specific scripts invoke them.
So, it seems I should add it to the component.plist, since they do not say anything about postupgrade. BUT it seems strange, I would put there more specific script, not the postupgrade script.
Reading more, I found it that refers to this, where there is written:
To determine whether a Package has already been installed or not, Installer.app is having a look at the content of the following directory: /Library/Receipts. If there's a file named PackageName.pkg within it, then the Package has already been installed, otherwise it's the first install.
Well, my application leaves no pkg file there, but yes it is present in the InstallHistory.plist.
Well, finally the question: should I set the upgrade script somewhere, for example in the component.plist file? The last link seems to be out of date, something has changed? How can I put a pkg file inside /Library/Receipts? Or better, how can be sure if my installation is indeed an installation and not an upgrade, or viceversa?
Thanks everyone, I am a bit confused...
What: I've a shell script that I'd like to distribute to my LUG.
I believe that a debian package will be the easiest way to distribute it. I want to create a .deb file for the script in this repository
Where: I want it to be placed in some directory like /usr/local/bin so that it is easy to execute and maybe create some symbolic links
Problem: How to write make file for it and/or other files and folders required to do that. I researched a lot when I tried to do it couple of months ago but no luck then. Here are the files from my previous attempt Now I'm trying to pack this for a tutorial on shell script in my LUG and facing similar situation again.
I'll be really glad if someone can be patient enough to guide me through it.
Any kind of resources or details will be much appreciated.
PS: I also intend to port the script to perl soon.
As mirabilos said, you should at least have a look to the packaging-tutorial written by Lucas Nussbaum, the current Debian Project Leader. You can install it directly from a Debian repository:
# apt-get install packaging-tutorial
Then, open and skim the PDF located at /usr/share/doc/packaging-tutorial/packaging-tutorial.pdf. After skimming it you'll have the basic knowledge needed to understand the structure of a Debian package.
Now let's get our hands dirty. mv your script to a new directory. The name of the directory must follow the nomenclature upstreamname-*version*.
rul#helicon:/tmp/a$ mkdir script-0.1
rul#helicon:/tmp/a$ mv script.sh script-0.1
cd to the directory where your script is and run dh_make --createorig. Choose single binary. You'll now have a debian/ directory with lots of file in it. This files are the ones you need to make your package. In your case, most, if not all, of the *.ex files are safe to be removed. Read and modify when needed the remaining files.
Now let's write the core of our package. You want to install a script in /usr/local/bin. The good news is that there is already a program that does that for you. You just have to specify the file name and where to put it. This program is dh_install. It has a very complete man page. After reading it, you should now understand that you have to create a install file in the debian/ directory.
rul#helicon:/tmp/a/script-0.1$ echo "script.sh usr/local/bin/" > debian/install
Here you have a real example of this file usage.
That's it! You have all you need to build your package. cd to the root directory of your package and run dpkg-buildpackage. If all went well, you'll have your fresh new .deb in ../.
You really should have a look at, in this order, the inofficial packaging tutorial, the Debian New Maintainers' Guide, Debian Developer's Reference and Policy. (The order is also increasingly dry, and reversed for formalness.)
It may take two days or so, but is really worth it.
Also, look at other small packages shipping only scripts, or other mere “file installers” (like php-htmlpurifier, first example I remembered while writing this).
If your package will only have a single file (or small number of files) in it, going through the full Debian toolchain might be overkill.
For packaging single files, I recommend you use the equivs tool. Install the equivs package, then run equivs-control to create a template file.
Edit the template file (give your package a name, version number etc.).
Add the name of your script to the Files: attribute in the template, for example:
Package: my-awesome-script
Version: 4.2
Files: my-awesome-script.sh /usr/local/bin
Section: misc
Priority: optional
Standards-Version: 3.9.2
Maintainer: Me <me#gmail.com>
Description: An awesome script doing stuff
Lorem ipsum etc. pp.
Put the script file alongside the template file.
Run equivs-build which will create your Debian package.
This is much easier for these simple cases than anything else – and the package that you get is standards compliant without resorting to any hacks or jumping through hoops.
for pre install, write your script in file DEBAIN/preinst;
for post install, write your script in file DEBAIN/postinst;
Use checkinstall or fpm to build your packages in minutes not hours or days!:
sudo checkinstall --fstrans=yes --install=no -D --pkgname=script \
--maintainer='Name <name#domain.tld>' --pkgarch=all --pkgversion=0.1 \
--nodoc cp script.sh /usr/local/bin
fpm -s dir -t deb --prefix /usr/local/bin -n script -v 0.1 -a all ./script.sh
Note: checkinstall requires dpkg/dpkg-deb (only works on Debian/Ubuntu), fpm is platform independent but requires ruby.