How to install difflib module in python 2.7 windows 10 - python-2.7

Currently, I am facing difficulty installing difflib module in python 2.7 version in windows 10 system.
I want it to perform some text analytics analysis
tried using
apt-get install npm
npm install difflib
and
pip.exe install difflib

Solution for me was to save the difflib.py in the location where your .py file resides and then import it in your file.

install using pip should be a great idea, You can refer to the module related details here:
https://docs.python.org/2.7/library/difflib.html
If you face an issue installing it using pip, then the next way is to get the difflib.py from any working machine and keep it in the project directory itself, so that just importing the module itself will work.
This is the codebase reference from svn of python itself:
https://svn.python.org/projects/python/trunk/Lib/difflib.py

Related

Linux python django site-packages not recognized in envelope

I have tried to create envelope on my linux pop os system using miniconda. When I activate it, I can install packages using pip, but when I run my django instance it doesn't find the modules.
If I type which python is shows the miniconda path correctly. I can look in the site-packages folder and see the packages installed.
I've tried installing django-anymail and corsheaders and they are both not being found. It does find my locally installed apps.
If I use the command line and open python and then import, it does not recognize my modules installed in the virtual envelope either. I thought it was a problem with conda, so I also created an envelope using python's native method: python3 -m venv
I have the same problem with it finding pip install site-packages.
Is there a command I can run to show all available packages?
I hadn't realized I had aliased my python. Now it is working.

How to create a RPM which install python dependencies?

I have a python application that has flask dependency.
All I need is to create an RPM out of this application and with this RPM I should be able to install the dependencies to another machine.
Things I have tried,
Created a setup.py file,
setup(
name='sample-package',
version='1.0.0.0',
author="Niranj Rajasekaran",
author_email="nrajasekaran#test.com",
package_dir={'': 'src/py'},
namespace_packages=['main'],
packages=find_packages('src/py/'),
install_requires=['Flask']
)
Ran this command
python setup.py bdist_rpm
Got two RPMs in dist/, one is noarch and other is src
I tried to install noarch rpm using this
yum install {generated-file}.rpm
I am able to get sample-package-1.0.0.0.egg file in site-packages but not flask.
Two questions,
Is my approach correct?
If so what is something that I am missing?
bdist_rpm lacks of a lot of functionality and IMO is not very well maintained. E.g. pyp2rpm is much better for converting existing PyPI modules. But your module does not seem to be on PyPI, so you need to specify it to bdist_rpm manually because it cannot retrieve this information from setup.py.
Run:
python setup.py bdist_rpm --requires python-flask
This will produce an rpm file which requires the python-flask package. For more recent RHEL/Fedora it would be python3-flask.

Unable to import docx in python3

I have installed both python2 and python3 in my windows machine. I wanted to use the python-docx, so I installed it using pip install . But I am unable to use it in python3. I get these results when i try to import in Python2:
]1
In Python3 :
]2
Python packages are installed in a particular Python installation. You have two Python installations and it looks like python-docx is installed in only one of them. What you need to work out is how to target the Python 3 installation for the python-docx install.
This question seems to address how to manage that.

How can I install h5py with Portable Python v2.7?

I am doing some Python 2.7 development work on multiple computers, on some of which I do not have rights to install software. Thus, I am using Portable Python. One of the packages I need to use is h5py; however, since Portable Python installs without modifying the registry, the h5py installer doesn't see it as a valid Python installation. Also, simply extracting the h5py source to a custom F:\py\include folder and adding F:\py\include to the PYTHONPATH environment variable doesn't work, as import h5py results in an ImportError: Cannot import name _errors exception.
How do I install h5py with Portable Python 2.7?
Install Python 2.7 onto a computer for which you have sufficient administrative rights.
Install the appropriate version of h5py into this Python installation.
Find the h5py subfolder within the Python install (typically .\Lib\site-packages\h5py) and copy it to the F:\py\include folder mentioned (make sure to add F:\py\include to PYTHONPATH). See my answer here for more details.
Uninstall the 'official' version of Python, if desired.

Is it possible to install a django package without pip?

I am trying to install django-dash to run one of the dashboard examples and see what it's like.
I am on Windows running Python 2.7 and Django 1.6.5. I know the usual approach is to download pip then install the package using pip. However, I am on a work computer with no administrative rights so I can't access my Internet Option Settings to find my proxy URL to follow the instructions below:
Proxy problems
If you work in an office, you might be behind a HTTP proxy. If so, set the environment variables http_proxy and https_proxy. Most Python applications (and other free software) respect these. Example syntax:
http://proxy_url:port
http://username:password#proxy_url:port
I had the same issue when trying to install Django but was able to get it to work by moving the django directory under Python27/Lib/site-packages. Is there something similar I can do with django-dash?
I also tried downloading the sources and running python setup.py install. I received the following error:
File "setup.py", line 3, in <module> from setuptools import setup, find_packages ImportError: No module named setuptools
Link to django-dash: http://django-dash.readthedocs.org/en/latest/
Yes, you can probably get the sources from The Python Package Index
Once you have them, uncompress the files and install them manually (this will depend on you OS).
On Linux systems:
python setup.py build
python setup.py install
Here's the full reference
EDIT : Note that when manually installing those packages, you must also install any missing dependencies, eg. setuptools in your case