Why should I create virtual environments for python projects? [closed] - python

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
All the time that I've worked with python and anaconda, I have never wondered how actually virtual envs are useful except for version controlling. When I looked it up, I found a lot of articles on how to create and use custom envs, but not exactly why they are so awesome. Why is it dangerous to install new libraries into the original installation? Are virtual envs useful for anything other than versioning?

PROS:
You can use any version of python you want for a specific environment without having to worry about collisions.
Your main python package directory does not get flooded with unnecessary python packages.
You can organize your packages much better and know exactly the packages you need to run.
Anyone can run your code on their machine.
Your project is easier to deploy.
Your application runs faster.
Ease of maintenance.
CONS:
storage space?

Related

Is sys.path.append() a good workaround? [closed]

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 2 years ago.
Improve this question
I am seeing some of my colleagues use the following workaround for importing external python modules (without installing them).
import sys
sys.path.append(<PATH_TO_MODULE>)
import <module>
sys.path.remove(<PATH_TO_MODULE>)
I don't think this is a good approach but "it works".
What should I suggest them to do instead of the following code and why?
Thanks!
It sounds as though your colleagues are not making virtual environments to run python and are trying to avoid muddy-ing the main python modules.
So I'd suggest they start seperating out their concerns and projects into seperate virtual environments where they don't need to worry about having modules installed.
See also conda environments and other alternatives to achieve the same goal
An alternative approach would be to append the module’s path to PYTHONPATH:
export PYTHONPATH="${PYTHONPATH}:/path/to/your/module/"
In this way, nothing is hardcoded in your source code and whenever something changes, you just need to export the new path to PYTHONPATH.

Clean install of python working environment [closed]

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 4 years ago.
Improve this question
I recently switched jobs and have the oportunity to create a clean programming working environment, cleaner and better than I used to have before. In my previous work I had some problems with running different versions of python next to eachother (or different versions of package) so I thought it would be a good idea to use Conda as a python install/package manager.
As an IDE I used to use idle because I find spyder a little cluttered, but I do however miss some functionality of a proper IDE and was thinking about switching to PyCharm for personal use and iPython (that is the same as python notebook isn't it?) for courses on python I will be giving.
What is the best way to do a very clean install? Do I install miniconda first and then python3.6 (and/or python2.7), pycharm, iPython? Or can I do this in a better way without getting to much clutter?
I would definitely suggest to go for miniconda or anaconda, as you already said yourself, since it allows you to keep different Python versions separated in different environments.
I cannot really give you advice on the editor to use, since I always use Spyder. It takes some time to get used to, but it very versatile and extremely useful when dealing with large and many Python scripts.

Basic steps to develop python API in Unix environment [closed]

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.

Should every python program be distributed with a setup.py? [closed]

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 8 years ago.
Improve this question
Disclaimer: I'm still not sure I understand fully what setup.py does.
From what I understand, using a setup.py file is convenient for packages that need to be compiled or to notify Disutils that the package has been installed and can be used in another program. setup.py is thus great for libraries or modules.
But what about super simple packages that only has a foo.py file to be run? Is a setup.py file making packaging for Linux repository easier?
Using a setup.py script is only useful if:
Your code is a C extension, and then depends on platform-specific features that you really don't want to define manually.
Your code is pure Python but depends on other modules, in which case dependencies may be resolved automatically.
For a single file or a few set of files that don't rely on anything else, writing one is not worth the hassle. As a side note, your code is likely to be more attractive to people if trying it up doesn't require a complex setup. "Installing" it is then just about copying a directory or a single file in one's project directory.

Django framework installation [closed]

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).

Categories