Anaconda: Where and how to install a non-distribution package to support a flask-wtf conda recipe? - python-2.7

I'm trying with little success to build and install conda packages in for envs in the Anaconda python distribution. Right now I'm trying to build a package for flask-wtf. I copied the .bat, .sh, and .yaml recipe files from Continuum IO's recipe. The files are in a directory named flask-wtf on my desktop, and I ran conda build flask-wtf on it. It returned the message: Error: No packages found matching: wtforms. I do not have wtforms installed anywhere, so now I have two questions:
1) If I install wtforms do I have to install it globally, or can I keep it in the relevant conda env?
2) If I install wtforms from a tarball do I have to keep that tarball file around for later installs into other envs?
Thanks for your help and clarification!

The only way that conda build will see dependencies is if they also exist as conda packages. So you need to build the conda package for wtforms as well. Fortunately, the recipe for this exists in the conda-recipes as well, so you can just clone that repo and do
conda build wtforms
conda build flask
This works because conda is able to find the packages that it has already built. To make sure that they don't get lost if you delete the build directory, it's recommended to upload your packages to Binstar. If you do that and conda install binstar, after you build, it will ask you if you want to upload the package to binstar. If you do that, and also add your Binstar repo to your .condarc, those packages will always be available for you to conda install.

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.

AWS Lambda (python2.7): Adding matplotlib as a layer

I am having trouble trying to add matplotlib as a layer to my Python 2.7 AWS Lambda function.
On the Lambda execution environment, I am trying to install the necessary libraries and create a layer as described here.
Things I've tried:
First, I pip installed matplotlib into a virtual environment and copied the contents of the site-packages under lib and lib64. When the lambda function is executed, I get a No module named pkg_resources exception. I also tried installing with the --target option to install all dependancies to the same folder. The result was the same.
I read here that it may be due to outdated setuptools package. When I did an update pip install --upgrade setuptools and then tried to install matplotlib I started getting the following exception:
pkg_resources.DistributionNotFound: The 'pip==9.0.3' distribution was not found and is required by the application
Finally I thought of installing matplotlib with
sudo yum install python-matplotlib
and then collect the required packages as described here. But this did not make matplotlib importable from within the python shell, so I guess it won't work as a Lambda layer.
Thanks for any help.
P.S: At AWS re:invent, exactly this was demoed but there are no details on the session :/
I encountered similar issues with other modules such as crypto and my own custom modules. I discovered the problem is really a lack of good documentation.
In my case, I was zipping all the dependencies up from the target directory, using the --target option, so all the dependency directories were at the top level of the zip file. That works fine for straight Lambda deployment, but when you want to use a layer, the layer is deployed in to the /opt folder of your Lambda container, so you need to create your zip file with a top-level directory named 'python' so that your dependencies can be located at /opt/python/.
mkdir python && cd python && pip install pyopenssl crypto --target . && cd .. && zip -r9 ./lambda_layer.zip python/
It does appear in the documentation but it is brief and VERY easy to miss. This page helped me: https://medium.com/#adhorn/getting-started-with-aws-lambda-layers-for-python-6e10b1f9a5d
Good luck!

Installing Python package from source into virtualenv directory

Newbie programmer here. This is a variation of this question and this question.
I am running Python 2.7 on Windows 7, and using git bash shell. I am trying to install the numpy package into a virtualenv directory in my work directory. I cannot install it using the $pip install -r requirements.txt or the $pip install numpy commands because of errors caused by its dependencies. Here is a log file for this install failure.
Although I can install numpy directly by downloading the executable binary (.exe) from sourceforge, but it forced me to install it in the c:/Python27/Lib/site-packages directory. I need to install it in my virtualenv work directory, e.g. c:/Users/MyName/Projects/myproject/myvirtualenv.
I need help on how to download the necessary numpy files into a temp directory, and how to use pip or another tool install it into my virtualenv directory.
I researched that I can choose a target directory using the -t option in pip, e.g., "pip install numpy --target=c:/Users/MyName/Projects/myproject/myvirtualenv". But I still can't get over the dependencies errors, so pip doesn't work for me unless I can figure out how to download the numpy files (including all dependencies) into a directory and then install from there.
Thanks for your help!

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