Found 27104 Articles for Server Side Programming

How to install python modules and their dependencies easily?

Rajendra Dharmkar
Updated on 01-Oct-2019 10:46:23

966 Views

The best and recommended way to install Python modules is to use pip, the Python package manager. It automatically installs dependencies of the module as well.If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setup tools, but will need to upgrade to the latest version:On Linux or macOS:pip install -U pip setuptoolsOn Windows:python -m pip install -U pip setuptoolsIf you’re using a Python install on Linux that’s managed by the system package manager (e.g "yum", "apt-get" etc…), and you want to use the system package manager to install or upgrade ... Read More

How to use remote python modules?

Rajendra Dharmkar
Updated on 01-Oct-2019 10:47:54

2K+ Views

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 knockoutNow 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/#packagenameThis 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 If you are not able to install modules on a machine(due ... Read More

How to call a function of a module from a string with the function's name in Python?

Rajendra Dharmkar
Updated on 11-Dec-2019 09:25:32

777 Views

Objects in python have instance variables and methods as attributes. To call a function of a module from a string with the function's name in Python, you can get this attribute first and call the function object attached to it. For example, let's say that I have a module foo, and I have a string whose contents are "bar". The best way to go about calling foo.bar() is:>>> import foo >>> method_to_call = getattr(foo, 'bar') >>> result = method_to_call()If you have the function in global or local namespace without the module prefix, you can also use globals()/locals(). locals returns a ... Read More

How I can install unidecode python module on Linux?

Rajendra Dharmkar
Updated on 01-Oct-2019 10:49:13

1K+ Views

To install unidecode or any other python module you need pip installed(python package manager). If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:On Linux or macOS:pip install -U pip setuptoolsOn Windows:python -m pip install -U pip setuptoolsIf you’re using a Python install on Linux that’s managed by the system package manager (e.g "yum", "apt-get" etc…), and you want to use the system package manager to install or upgrade pip, then see: https://packaging.python.org/guides/installing-using-linux-tools/Otherwise:Download get-pip.py from https://bootstrap.pypa.io/get-pip.py. Run python get-pip.py. This will ... Read More

Is there something available in Python like PHP autoloader?

Rajendra Dharmkar
Updated on 30-Jul-2019 22:30:20

235 Views

No there is not. And you should not try something like that in Python. There's a good reason for autoloading in PHP which is that PHP scripts are executed from scratch every time you load some page. The opcodes may be cached and files may be already prepared, but the main point remains - importing another file actually means making sure its contents are loaded.In Python webservices, your files are not reread every time. If you import something, its imported for the lifetime of the app. Autoloaders in Python would be used only one time, not on each request.So autoloaders ... Read More

How to develop a Python Module?

Pranathi M
Updated on 16-Sep-2022 07:19:09

441 Views

A file containing Python commands and definitions is referred to as a module. These files named .py which contain that contains Python code, such as example.py, and the name of the module is an example. Modules are used to divide down huge applications into smaller, more manageable files. The prerequisites for using modules you should have Python 3 installed and a programming environment set up. If you don't already have one, you can refer to the installation and setup recommendations for a local programming environment. Example 1 Let us look at an example to create a simple python module. Let ... Read More

Where are the python modules stored?

Rajendra Dharmkar
Updated on 01-Oct-2019 07:05:04

3K+ Views

Python Modules are usually stored in /lib/site-packages in your Python folder. If you want to see what directories Python checks when importing modules, you can log the following:>>> import sys >>> print sys.path ['', 'C:\Python27', 'C:\Python27\Lib\site-packages', 'C:\Python27\Lib', 'C:\Python27\DLLs', 'C:\Python27\Lib\lib-tk', 'C:\Python27\Scripts', 'C:\WINDOWS\SYSTEM32\python27.zip', 'C:\Python27\lib\plat-win', 'C:\Python27\lib\site-packages\win32', 'C:\Python27\lib\site-packages\win32\lib', 'C:\Python27\lib\site-packages\Pythonwin']You can also list where individual modules being used by a script(say hello.py) reside on the system using the python -v command. For example, $ python -v hello.py PS C:\Users\Ayush> echo 'import scrapy' > hello.py PS C:\Users\Ayush> python -v hello.py # installing zipimport hook import zipimport # builtin # installed zipimport hook # C:\Python27\Lib\site.pyc matches C:\Python27\Lib\site.py ... Read More

How do you dynamically add Python modules to a package while your programming is running?

Rajendra Dharmkar
Updated on 01-Oct-2019 07:06:04

370 Views

To dynamically import Python modules, you can use the importlib package's import_module(moduleName) function. You need to have moduleName as a string. For example, >>> from importlib import import_module >>> moduleName = "os" >>> globals()[moduleName] = import_module(moduleName)If you want to dynamically import a list of modules, you can even call this from a for loop. For example, >>> import importlib >>> modnames = ["os", "sys", "math"] >>> for lib in modnames: ...     globals()[lib] = importlib.import_module(lib)The globals() call returns a dict. We can set the lib key for each library as the object returned to us on import of a ... Read More

How to install libxml2 with python modules on Mac?

Rajendra Dharmkar
Updated on 01-Oct-2019 07:07:08

644 Views

You can install libxml2 using the following commands:$ brew install --framework python $ brew install --with-python libxml2 $ brew install --with-python libxslt $ brew link libxml2 --force $ brew link libxslt --forceIf you had already installed libxml2 but it had failed or any other error, you can uninstall it and then reinstall it using:$ brew unlink libxml2 $ brew uninstall libxml2 $ brew unlink libxslt $ brew uninstall libxslt

How to install python modules without root access?

Rajendra Dharmkar
Updated on 01-Oct-2019 07:07:43

676 Views

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 directory:>>> 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 ... Read More

Advertisements