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.
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
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?
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.
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 7 years ago.
Improve this question
i have heard this is an environment variable but Can someone tell me the purpose of PYTHONSTARTUP?
PYTHONSTARTUP is an environment variable you will define specifying the location of the path to a python file.
This python script will be run by python before starting the python interactive mode (interpreter). You can use it for various enhancements like preloading modules, setting colors. (Here) is a helpful post.
Developers use something called dotfiles to enhance the bash environment. Lookup github for sample dotfile scripts which enhances the bash. You can use it with a similar state of mind. Here is a github startup script.
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.
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
I'm writing a script for a colleague who runs Windows but my development environment is GNU/Linux.
I have a bunch of variables that need to be configurable. So I put them all in a config.py that I've imported it into the main project.
Originally I planned to ask him to install Cygwin but then I thought of packaging it into an exe with py2exe or pyinstaller. I've not used either of these before so I don't know how they work. Would I have problems with the config.py file or should I be using an actual module like ConfigParser to store my settings so that it can be separate from the .exe file?
The problem you would have is that if your friend decided to change something in the config, he'd have to ask you to do it, run py2exe again and send the .exe to him again. With an .ini file, he'd simply edit the file.
I would definitely use a config parser or even just a json or ini file.