- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use remote python modules?
There are ways to import Python modules remotely. It is not recommended to do so though as it will slow down your app. You can use the knockout module to achieve this. To install knockout use:
$ pip install knockout
Now in order to import modules remotely, you can use knockout like:
>>> from knockout import urlimport >>> urlimport.register() Url importing enabled. Add urls to sys.path.
A valid url looks like this: http://example.com/path/to/repository/#packagename
This stuff is experimental, use at your own risk. Enjoy.
>>> import sys >>> sys.path.insert(0, 'http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.0.8/#BeautifulSoup') >>> import BeautifulSoup ... >>> BeautifulSoup <module 'BeautifulSoup' from 'http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.0.8/BeautifulSoup.py'>
If you are not able to install modules on a machine(due to not having enough permissions), you could use either virtualenv or save the module files in another directory and use the following code to allow Python to search for modules in the given module:
>>> import os, sys >>> file_path = 'AdditionalModules/' >>> sys.path.append(os.path.dirname(file_path)) >>> # Now python also searches AdditionalModules folder for importing modules as we have set it on the PYTHONPATH.
You can also use virtualenv to create an isolated local Python environment. The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded. This can also be used in our use case where we cannot install the package on the machine as we dont have the permissions. For more info on virtual env, read the docs: https://virtualenv.pypa.io/en/stable/
- How to use Python modules over Paramiko (SSH)?
- How to use multiple modules with Python import Statement?
- How do we use easy_install to install Python modules?
- How to use pip to install python modules in easy way?
- Is it possible to use Python modules in Octave?
- How do Python modules work?
- How to check version of python modules?
- How to deploy python modules on Heroku?
- How to install Python modules in Cygwin?
- How to Use SFTP to Secure File Transfer with a Remote Server
- How to install python modules without root access?
- Reloading modules in Python?
- Locating Modules in Python
- How we can bundle multiple python modules?
- How to encapsulate Python modules in a single file?