Found 34494 Articles for Programming

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

239 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

444 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

371 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

648 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

684 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

Can we iteratively import python modules inside a for loop?

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

2K+ Views

Yes you can iteratively import python modules inside a for loop. You need to have a list of modules you want to import as strings. You can use the inbuilt importlib.import_module(module_name) to import the modules. 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 module.

What is the most compatible way to install python modules on a Mac?

Rajendra Dharmkar
Updated on 01-Oct-2019 07:09:57

184 Views

The most popular way to manage python packages (if you're not using your system package manager like homebrew) is to use setuptools and easy_install. It is probably already installed on your system. Use it like this:easy_install djangoeasy_install uses the Python Package Index which is an amazing resource for python developers. Have a look around to see what packages are available.A better and more reliable way to install python modules across platforms is to use pip. 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 ... Read More

What are the best practices to organize Python modules?

Rajendra Dharmkar
Updated on 01-Oct-2019 07:10:31

410 Views

Here is a sample project that shows a very good way to structure your projects: https://github.com/kennethreitz/samplemod. The project is about creating the "sample" module. The directory structure looks as follows:README.rst LICENSE setup.py requirements.txt sample/__init__.py sample/core.py sample/helpers.py docs/conf.py docs/index.rst tests/test_basic.py tests/test_advanced.pyThe README.rst file: This file is for giving a brief description of the module, how to set it up, how to use it, etc.LICENSE: Contains license text and any copyright claims.setup.py: It is Python's answer to a multi-platform installer and make file. If you’re familiar with command line installations, then make && make install translates to python setup.py build && python ... Read More

Advertisements