I'm fairly noob at the using the terminal and doing server administration. I recently "inherited" a Twitter app, and I need to install a Python OAuth library:
http://dev.twitter.com/pages/oauth_libraries#python
Unfortunately, I'm pretty much clueless about how to:
download a library to the server
installing the library on the server so I can "import "
Can someone please walk me through this process? Or, provide me with resources that will?
Thanks!!
The easiest solution is probably to run 'easy_install' as root using the same python that runs the application (there may be different versions of python). You may need to install a package such as 'setuptools' first, or download and run the easy_install-installer as follows:
# wget http://peak.telecommunity.com/dist/ez_setup.py
# python ./ez_setup.py
But again, only do this if you don't have easy_install
The 'best' way to do it depends on how you run your application (mod_python, cgi or wsgi). With WSGI the best way would be to have a seperate virtualenv for each site in which you install things for that site only. This way you can have different versions of the same library installed which is also a big plus for development but even more so for websites where you might want to keep one website on the older version of a lib and another on the newer version.
A few links to get you started:
WSGI + virtualenv,
virtualenv
Any question you can add as a comment.
Related
I'm integrating a java project by using maven. This project should be pushed to a server(linux) with limited access(cannot use pip). I've added all the dependencies for my java component adding them to the pom.xml, but In part of my code I've used client/server approach to call a python script, which requires Pandas and Sklearn. Unfortunately, I've memory issue and cannot copy the entire directory of these libraries into server.
I'm afraid if maven could help me to download the python dependencies or if there is another efficient way of adding python dependencies into repository. I've done some research but couldn't find any helpful way to address that. I'm a beginner in python and I'd be happy if you could help me address that.
If limited access (Assuming you can download but cannot install) is your issue you can download Anaconda and it doesn't need to be installed with root access. It install everything to your home directory and creates a virtual environment for you. That way you can use pip too. Just make sure you call your python script with your anaconda virtual environment python.
/home/USER/anaconda2/envs/ml/bin/python script_name.py
Long time reader, first time OP.
I've written a program using 'Beautiful Soup' from the 'bs4' library and the 'requests' library (which is the most amazing thing, achieved in less than five minutes what I had failed to do in a week with urllib2), both of which I had to install (I'm using PyCharm CE).
If I'm sharing this file, what's the best way to make sure these modules are folded in with the package if I send it to someone? Or post it somewhere?
I'm running Python 3.5.2 in PyCharm CE
Thanks in advance!
You are probably asking about packaging and distributing python projects. That document describes how to package your project and upload it to PyPI.
If you only want to share a snippet of code, tell those who you are sending it to to install dependencies first via pip. Share the needed pip install <package> commands list.
I am trying to begin a new python GUI application and I have decided to use wxPython as GUI because I want a multi-platform one.
The problem is that I want to use virtualenv ( with virtualenvwrapper ) to isolate the environment and be able to reproduce it in other machines where I will work, but i cannot install wxPython.
I have it installed in my ubuntu machine via apt-get but that is not enough
I have searched the web for a solution and i have found ...
This page http://batok.github.com/virtualenvwxp/ where it is explained a way to hack the virtualenv environment to use the local installation of wxPython. Not the best solution, but it would be a good workaround. The problem is that it is explained for Mac, and I couldnt make it work in my ubuntu.
Also found this page Installing wxPython in virtualenv under Linux where someone ask something similar. I have tried to build wxPython that way with no success.
Any help would be appreciated.
In the end, I have choose wxPython beacuse it is multiplatform and i can use it without license problems, but as i have not started yet i can change my mind if there is another easier to install framework.
Thanks In advance
20110925: Sorry for the delay and thanks for the answers.
I just have tried to install wxpython using buildout and the links given here, but i still have the same problem. It seems as if I need libgtk2.0-dev package to be able to compile wxpython...
So there is any way to install this package locally to the buildout environment?
Thanks again.
At the end I could not resolve this problem.
I want to create a reproducible python environment with all the requirements inside using buildout and/or virtualenv so I could work in any linux system with just virtualenv, python and a C++ compiler installed.
It seems that the only way to do this is to use buildout cmmi recipes to download and build wxpython and ALL its dependencies. This is a really painful way, and I have no time now.
I have decided to use a workaround: I am going to work on my ubuntu laptop most of the time, so I have installed wxpython from the repositories and use a wx.pth file to make it available to the virtual environment.
This is not a good solution, but seems the best till now ... so if someone knows any better solution please let me know.
When my python project is more mature, I will turn again to this problem and I will probably try the hard way ...
Thanks for all your answers and comments.
The solution I ended up using was to install python to my main system:
Then make a symbolic link from the wx in my system python to my virtual environment:
ln -s /usr/lib/python2.7/dist-packages/wxversion.py <virtual_env_path>/lib/python2.7/site-packages/wxversion.py
Where is the path in my case to a virtual environment named "fibersim" for example is:
/home/adam/anaconda/envs/fibersim
Then import wx worked
Got this from: http://qopml.org/wp-content/uploads/2013/01/README.txt
Buildout allows your to install different parts whose recipe code determines how that part is built. There are cmmi recipes for building stuff with Configure/Make/Make-Install (CMMI). You can use this to build wxPython locally to the buildout and then create a python interpreter that has that build of wxPython and your own eggs in it's path.
See this blog post and this answer for details.
Keep in mind that zc.recipe.egg will also install any setuptools/distribute console_scripts in the buildout's bin directory as well. See also mr.developer for automatically checking out multiple packages from VCS and working on them in the same buildout.
I am trying to define a process for migrating django projects from my development server to my production server using git, and it's driving me crazy that distutils installs python modules system-wide. I've read the documentation but unless I'm missing something it seems to be mostly about how to change the installation directory. I need to be able to use different versions of the same module in different projects running on the same server, and deploy projects from git without having to download and install dependencies.
tl;dr: I need to know how to install python modules, using distutils, into my project's source tree for version control without compromising other projects using different versions of the same module.
I'm new to python, so I apologize in advance if this is common knowledge.
Besides the already mentioned virtualenv which is a good option but has the potential drawback of requiring a third-party module, Distutils itself has options to install modules into arbitrary locations. In particular, there is the home scheme which allows you to "build and maintain a personal stash of Python modules". It's described in the Python documentation set here.
Perhaps you are looking for virtualenv. It will allow you to install packages into a separate virtual Python "root".
for completeness sake, virtualenvwrapper makes every day work with virtualenv a lot quicker and simpler once you are working on multiple projects and/or on multiple development platforms at the same time.
If you are looking something akin to npm or yarn of the JavaScript world or composer of the PHP world, then you may want to look at pipenv (not to be confused with pip). Here's a guide to get you started.
Alternatively there is also Poetry, which some people say is even better, but I haven't used it yet.
I'm building a Django app, which I comfortably run (test :)) on a Ubuntu Linux host. I would like to package the app without source code and distribute it to another production machine. Ideally the app could be run by ./runapp command which starts a CherryPy server that runs the python/django code.
I've discovered several ways of doing this:
Distributing the .pyc files only and building and installing all the requirements on target machine.
Using one of the many tools to package Python apps into a distributable package.
I'm really gunning for nr.2 option, I'd like to have my Django app contained, so it's possible to distribute it without needing to install or configure additional things. Searching the interwebs provided me with more questions than answers and a very sour taste that Django packing is an arcane art that everybody knows but nobody speaks about. :)
I've tried Freeze (fails), Cx_freeze (easy install version fails, repository version works, but the app output fails) and red up on dbuilder.py (which is supposed to work but doesn't work really - I guess). If I understand correctly most problems originate form the way that Django imports modules (example) but I have no idea how to solve it.
I'll be more than happy if anyone can provide any pointers or good resources online regarding packing/distributing standalone Django applications.
I suggest you base your distro on setuptools (a tool that enhances the standard Python distro mechanizm distutils).
Using setuptools, you should be able to create a Python egg containing your application. The egg's metadata can contain a list of dependencies that will be automatically installed by easy_install (can include Django + any third-party modules/packages that you use).
setuptools/distutils distros can include scripts that will be installed to /usr/bin, so that's how you can include your runapp script.
If you're not familiar with virtualenv, I suggest you take a look at that as well. It is a way to create isolated Python environments, it will be very useful for testing your distro.
Here's a blog post with some info on virtualenv, as well as a discussion about a couple of other nice to know tools: Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip
The --noreload option will stop Django auto-detecting which modules have changed. I don't know if that will fix it, but it might.
Another option (and it's not ideal) is to obscure some of your core functionality by packaging it as a dll, which your plain text code will call.