Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am developing an API in Unix environment for virtual machines. Most of the modules are developed in python. I have few questions on this.
I have the file extension as abc.py . I would like to make this as a command. For example , "virtman dominfo [vmid]" should be the command syntax. Now I have to give "virtman.py dominfo [vmid]" to achieve this. So how can make this as a command?
I want to make this as an installable API, I mean to install through apt-get/ yum install. What are the steps I need to do to achieve this or some reference URL's would be helpful.
Inside the API I am using absolute path like '/root/virtman/manager/' . Consider running this API in any unix environment , how can I make this absolute path generic to any OS/machine. Or should I have to assume some location where the API will get installed and give that path everywhere?
I read lot of articles but I didn't get the clear picture,so any hints/suggestions would be helpful.
This seems like it's three questions in one, so I'll attempt to answer each in turn:
File Extensions
Python scripts don't need to have a .py extension in order to be run. For example:
#!/usr/bin/python
print("Hello, World!")
Save this as a file called hello and flag it as executable. You should be able to run it from a terminal window by entering ./hello
apt-get / yum
Different systems use different packaging systems. For example, Debian and derivatives such as Ubuntu use .deb files, while Red Hat and co. use .rpm instead (though Debian can load .rpm files via the "Alien" tool). Each is slightly different, so I can't really give you a "generic" answer - hopefully this should be enough to get you started: https://fedoraproject.org/wiki/How_to_create_an_RPM_package
Generic Paths
You should be okay if you stick to the usual /var, /etc, /tmp layout - see this Wikipedia page for details.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am a complete, absolute beginner so please excuse my ignorance!
I have created my first 'coding project' using Visual Studio Code IDE in Python, here is a link to it below:
https://github.com/monicaneill/Projects/blob/master/guessinggame.py
Basically my question is how do I show this to others in a way that they can interact with it and not just look at a bunch of text? I'm really proud of my achievement and want other people to be able to play the game who might not have the likes of Visual Studio etc to run the code, is there any way I can do this so someone on say Facebook could open up a file and then run the game?
Thank you so much and apologies in advance if this is not the right place to ask this sort of question!
A python file needs the python runtime to be run. With the python runtime on your system, you can simply do, in your terminal-
> python guessinggame.py
(assuming guessinggame.py is on the same directory)
However, I assume you want people to be able to run the code without having the python runtime installed.
In that case, you need to compile your python code to an executable native binary. There are tools to aid in this process - perhaps the most straightforward tool is pyinstaller
Firstly, you need to install pyinstaller in your own system-
pip install pyinstaller
Now, in your terminal, you simply have to do-
pyinstaller guessinggame.py
(Make sure you're on the same folder where guessinggame.py is)
This will create a folder on the same directory that contains all the files needed to launch your script as well as an .exe (if you're on windows) - your friends will only need this folder and all they have to do is run the .exe
You can find more information about pyinstaller and how to make executables with it here
Search by flask -> documentation
I think this is more or less what you are looking for.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
Please forgive my ignorance. I'm using Mint 18.1. I installed Python 3.6 from its source code but it failed.
if I enter python, version 2.7 runs.
if I enter python3, version 3.5 runs (both were preinstalled with my Mint)
if I enter python3.6, i get a 'command not found' error.
Then I found and followed Error Installing Python.
My question is how to do i set it up so python3.6 runs without having to enter $HOME/py36/bin/python in the terminal.
Thanks
edit
NEVERMIND. got it. thanks a lot, guys.
You could add an alias in your shell's config file (.bash_profile or similar, if you're using bash) that points python3 to $HOME/py36/bin/python.
To do this, you need to find your shell configuration file (~/.bash_profile, ~/.bash_login, or ~/.profile) and edit it so that it contains an alias. Aliases take the form of newcommandname='oldcommandname -flags', so you want something like python3="$HOME/py36/bin/python". Note how there are no spaces around the equals sign, and double quotes, as that is required for this to work.
Alternately, you could add $HOME/py36/bin/ to your $PATH variable, so that your shell automatically looks there for binaries. You can do this by editing your shell configuration file like above to say PATH="$HOME/py36/bin/:$PATH". This makes your shell look here for executables before anything else; PATH="$PATH:$HOME/py36/bin/" will cause your shell to look for executables here after looking everywhere else. I don't recommend this, tbh; do the first one.
The best way to maintain several different versions of python is via conda, which allows you to create a variety of environments with different Python versions and packages. Conda is part of the Anaconda scientific Python distribution.
Anaconda
There are lots of tutorials on YouTube and the web.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have installed django framework with Python 2.7 and created all the paths. The problem is that whenever I type
django-admin.py command
the file itself is opening up. I am using Windows 7 64 bit.
Thank you.
You need to type
python django-admin.py command
If you get an error saying 'python is not recognized as an internal or external command..' you also need to add the python path to your environment path.
The problem is that .py files are not associated with python, so it gets treated as a normal txt file. You can either:
python django-admin.py command
(and see #VladSchnakovszki answer for errors which might pop up with that command), Or configure the files by right clicking > Properties, then (under General options):
Point it to python.exe and tell it to associate all files with the same extension with python as well.
P.S. a personal recommendation: When working in a windows environment I've had a good experience with installing ActiveState Python. It automatically sets the required paths, and also installs pip and other goodies that you'll probably need along the way (don't be scared of the priced version, there's a free community version too).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is it possible build python in my assigned directory on a Unix machine that I SSH to? Since this is a work server, do I need to make this aware to the system administrator if I want to try this. I want to use python instead of perl for advanced text manipulation.
You can do that following Python building instructions. They are pretty standard configure/make/make-install invocations. Just make sure to pass --prefix=~/local to configure script, so that it installs into your home directory because you probably don't have rights to install in /usr/local. You may need to ask your sysadmin to install extra development packages though, without them python or some python modules may fail to build.
If you can not get the required development packages installed on your server, another option is to build it on your own desktop, where you can install all required development packages, probably in a virtual machine matching the OS of the target box, and then just rsync/scp the directory where you installed it to the same directory on the target machine.
Yet another option is to find a privilege escalation exploit for your kernel, become local root and do whatever you want, but this is likely to get you in trouble. From a pure technical perspective though, it could be doable provided you are so determined to manipulate strings with Python.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm a designer who writes mostly Sass, Less (CSS pre-processors), HTML, Javascript and usually starts off with static site generators such as Jekyll, Yeoman, etc. While working with developers who code in Python, Ruby, Clojure, I help with the templates. In my free time, I design wordpress themes and write plugins in PHP. I run grunt regularly and bower helps me with components that I need for my designs.
This means my system is littered with Ruby Gems, Python libraries, Node Modules. They are either installed via gem installations, pip, brew or npm. Now you realize that my system is a mess even though it works. I really want to do stuffs in a sane manner, the right way.
So, what are the best practices for installation and management of all the libraries, core tools, etc. for a developer on Mac OS X. Point me to resources that I can read, ponder and practice.
Here is the scenario. You're a seasoned developer and I'm your friend who just got a new Mac OS X system. I'm a designer who will work with Python (mostly with Django), Ruby (with Rails), Clojure, PHP, Sass, Less, Compass, CoffeeScript, Git, NodeJS, Grunt, Bower, Jekyll, Yeoman and alike. As a friend, you know that I'm not a 'programmer' but a developer-friendly 'designer'. How can you help me setup my Mac? And I don't want to come back again when I get a new Mac in future, I should be able to just transition smoothly from my old setup.
Thanking in anticipation.
Github open sourced there developer environment setup tools. You could try that out. http://boxen.github.com/
For python I recommend using virtualenv to setup libraries instead of installing them globally. https://pypi.python.org/pypi/virtualenv
I am not sure what you meant by "How can you help me setup my Mac?". It seems that you are very much comfortable installing all the dependencies(gems and all) for your projects. If you want to automate all these environment installation setup then you may go ahead and write a generic shell script to install ruby, python and other stuff and reuse when you have a new machine :) and it has nothing to do with Mac OSX or any other OS. You just need to put correct package/version to fetch and install/compile accordingly in the script.
Would be great if you can put a specific question here in case you are facing technical problem installing any of the above packages.
If all that you are worried about is quickly setting up a new machine, use a backup software to setup the new machine. You can also try to use a custom time machine setup with just the folders that you are interested it.