Yuglify compressor can't find binary from package installed through npm - django

I have a fresh virtualenv environment and have got the latest django-pipleline.
The JS compression with Closure works perfect, but CSS compression with Yuglify fails, due a node error:
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.closure.ClosureCompressor'
PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'
When I try to collect the static:
./manage.py collectstatic
It says:
pipeline.compressors.CompressorError: /usr/bin/env: node: No such file or directory
But I have clearly installed yuglify even as global:
sudo npm -g install yuglify
/usr/local/bin/yuglify -> /usr/local/lib/node_modules/yuglify/bin/yuglify
yuglify#0.1.2 /usr/local/lib/node_modules/yuglify
├── uglify-js#1.3.4
├── ycssmin#1.0.1
└── nopt#2.1.1
Trying to set the biney in settings doesn't help either:
PIPELINE_YUGLIFY_BINARY = '/usr/local/bin/yuglify'
I still get the same error. Why now such problems with npm? Is there something I have to setup additionally?
Alternatively is there a way to install yuglify with pip?
Many Thanks,

After 3 hours of suffering, I have found the solution.
This is happening because of a misnaming error, if you install from a package manager (npm) your bin may be called nodejs so you just need to symlink it like this:
ln -s /usr/bin/nodejs /usr/bin/node
Now it is working. This didn't happen with the older version, its is something new. But at least it is working again. I hope this helps someone else out there. :)

In my case both uglify-js and cssmin were somehow not installed.
So I have re-installed them again by using following command and then it starts working again.
sudo npm install -g cssmin uglify-js

Related

heroku python buildpack pip install not adding the entry-points.txt file when installing

My runtime is python-3.7.5
I have an Django reusable app with an entry point in setup.py defined as:
setup = (
...
entry_points={'my.group': 'foo = bar'},
)
That allows me to use pkg_resources.iter_entry_points(group="my.group", name=None) to get a list of plugins.
I didn't know that until I had this bug, but it seems to rely on a entry_points.txt file that gets installed in the egg-info.
This entry_points.txt file seems to be missing when I push to heroku. I did a heroku run bash and:
~/.heroku/python/lib/python3.7/site-packages/m_package.egg-info $ ls
dependency_links.txt installed-files.txt PKG-INFO SOURCES.txt top_level.txt
but when I uninstall it and install it manually, and I recheck:
~/.heroku/python/lib/python3.7/site-packages/my_package.egg-info $ ls
dependency_links.txt entry_points.txt installed-files.txt PKG-INFO requires.txt SOURCES.txt top_level.txt
Am I missing something that the buildpack does?
The only extra thing to add is that I'm using https://github.com/timshadel/heroku-buildpack-github-netrc.git to get Https authentication in git, (my requirements.txt has some packages from private github repos) but I don't think that this should matter at all.
After messing with the official django buildpack, I realized it's just caching the packages, and since I updated my_package's code but not its version, it was not picking up the new library, hence no entry points. When I was doing pip install by hand on the heroku instance, it was picking the right library.
Good to know anyway, so keeping the question and the answer if anyone has the same problem one day.

python - pip installs but cannot import

I've read a lot of posts about this but none of the solutions have worked for me. I'm trying to get a module called nsxramlclient installed, shows successful installation with pip but cannot import from any location outside of the /Users/Nathan/Library/Python/2.7/lib/python/site-packages.
Uninstall does work after some fidgeting with brew using the recommendations found with brew doctor. Here are some vitals:
Running OSX python 2.7.10
PIP 18.1
which -a pip = /usr/local/bin/pip
which -a python = shows 2 directories:
/usr/local/bin/python
/usr/bin/python
python -c 'import sys; print(sys.path)'
['', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload']
pip list | grep nsxramlclient
nsxramlclient 2.0.7
It has to be a path issue since I'm able to import it from the directory that the module is located. I just don't know the proper method to repair this since I'm fairly new to Python and I don't want to mess it up worse that it is already.
Looks like I did end up getting it to work finally. What I had to do was to re-install python with brew:
brew re-install python#2
then I needed to re-install the modules I needed with pip. Having OTHER issues now but at least this one is fixed.

Setting up qt4py2 with with python 2.7 in virtualenv - cannot find the files :(

hopefully this question fits here, I have tried googling and reading "http://pyqt.sourceforge.net/Docs/PyQt4/installation.html" but unfortunately I'm such a newbie in all things linux that I cannot figure out what applies here...
anyway:
I have a virtual env (in Python 2.7)
I am trying to set up labelImg as instructed in : https://github.com/tzutalin/labelImg, specifically I run (with my virtualenv active):
sudo apt-get install pyqt4-dev-tools
sudo pip install lxml (<- did run this as "pip install lxml")
Then I run into problems with this:
make qt4py2
I got error:
"make: *** No rule to make target 'qt4py2'. Stop."
Now from googling I got the impression that I should be in the same directory as the make file when I run make (is this even true?), but when I try to find where pyqt4 is, I cannot find the folder (it is not in ~/.virtualenvs/virP2/lib/python2.7/site-packages$ (virP2 is the name of the virtualenv)
I have also tried to run (with the virP2 still active)
sudo apt-get install python-qt4
but I got:
"python-qt4 is already the newest version"
and I still cannot find where the directory with qt4 files is. (I also looked into the python2.7 folder outside the virtualenv, but it was not there)
Thanks for any advice!

Import Error with certain modules in pyoptsparse

Hello everyone,
I have installed Openmdao, pyOpt and pyoptsparse on my computer. As my program works with the Scipy optimizer, I tried it with a random optimizer of pyoptsparse (that was 'ALPSO'). It worked and I was happy. But it turns out it seems to be the only one working.
Every time I try to use another one (like 'SLSQP', which is the default optimizer !), i get this message "pyOptSparse Error : There was an error importing the compiled SLSQP module", inside a frame made of '-' and '+'.
Does anybody know what to do ? I am using Ubuntu if it changes something.
Thanks to swryan for the link, i found the answer.
One of the possible answer was to put libgfortran.so.3 in anaconda2/lib, but i already had it.
They were also saying the problem was solved when installing anaconda 4.0+ but i also had the latest version.
What worked for me was to run : conda update libgfortran --force
Doing it without the --force retrogrades the scipy, which seems to disable scipy.optimize.least_squares. If you did that, you can then run conda update scipy --force
Did you get any errors when you ran 'python setup.py install' for pyoptsparse? I looked at the setup.py file for pyoptsparse and there are some instructions in there that you could try:
print("\nTo install, run: python setup.py install --user\n\n"
"To build, run: python setup.py build_ext --inplace\n\n"
"For help on C-compiler options run: python setup.py build --help-compiler\n\n"
"For help on Fortran-compiler options run: python setup.py build --help-fcompiler\n\n"
"To specify a Fortran compiler to use run: python setup.py install --user --fcompiler=<fcompiler name>\n\n"
"For further help run: python setup.py build --help"
)

From virtualenv, pip freeze > requirements.txt give TONES of garbage! How to trim it out?

I'm following this tutorial:
http://devcenter.heroku.com/articles/django
At some point I'm suposed to do:
pip freeze > requirements.txt
(Ofc. from virtualenv created instance of python)
And I get this:
(venv)przemoli#ubuntu:~/Programowanie/hellodjango$ cat requirements.txt
BeautifulSoup==3.2.0
Brlapi==0.5.5
CherryPy==3.1.2
ClientForm==0.2.10
Django==1.3
GnuPGInterface==0.3.2
PAM==0.4.2
PIL==1.1.7
Routes==1.12.3
Twisted-Core==11.0.0
Twisted-Names==11.0.0
Twisted-Web==11.0.0
WebOb==1.0.8
adium-theme-ubuntu==0.3.1
apt-xapian-index==0.44
apturl==0.5.1ubuntu1
chardet==2.0.1
command-not-found==0.2.44
configglue==1.0
cssutils==0.9.8a1
defer==1.0.2
distribute==0.6.19
django-tagging==0.3.1
dnspython==1.9.4
duplicity==0.6.15
gnome-app-install==0.4.7-nmu1ubuntu2
httplib2==0.7.2
jockey==0.9.4
keyring==0.6.2
launchpadlib==1.9.8
lazr.restfulclient==0.11.2
lazr.uri==1.0.2
louis==2.3.0
lxml==2.3
mechanize==0.1.11
nvidia-common==0.0.0
oauth==1.0.1
onboard==0.96.1
oneconf==0.2.6.7
papyon==0.5.5
pexpect==2.3
piston-mini-client==0.6
protobuf==2.4.0a
psycopg2==2.4.4
pyOpenSSL==0.12
pycrypto==2.3
pycups==1.9.59
pycurl==7.19.0
pyinotify==0.9.1
pyparsing==1.5.2
pyserial==2.5
pysmbc==1.0.10
python-apt==0.8.0ubuntu9
python-dateutil==1.4.1
python-debian==0.1.20ubuntu2
python-virtkey==0.60.0
pyxdg==0.19
sessioninstaller==0.0.0
simplejson==2.1.6
system-service==0.1.6
ubuntu-sso-client==1.4.0
ubuntuone-couch==0.3.0
ubuntuone-installer==2.0.0
ubuntuone-storage-protocol==2.0.0
ufw==0.30.1-2ubuntu1
unattended-upgrades==0.1
usb-creator==0.2.23
virtualenv==1.6.4
wadllib==1.2.0
wsgiref==0.1.2
xdiagnose==1.1
xkit==0.0.0
zope.interface==3.6.1
When deploying on heroku it fails at Brlapi .....
I see lots of stuff from my main python installation which is on ubuntu. Which is BAD since Ubuntu use python for quite a few thing itself (ubuntu-one, usb-creator, etc..).
I do not need them on heroku! I need only Django, psycopg2, and their dependencies.
I do not even know if its fault of pip, or virutalenv. (If you want to know my setup look at link above I copied it into terminal)
That is one thing that has bugged me too quite a bit. This happens when you create a virtualenv without the --no-site-packages flag.
There are a couple of things you can do:
Create virtualenv with the --no-site-packages flag.
When installing apps, dont run pip install <name> directly, instead, add the library to your requirements.txt first, and then install the requirements. This is slower but makes sure your requirements are updated.
Manually delete libraries you dont need. A rule of thumb i follow for this is to add whatever is there in my INSTALLED_APPS, and database adapters. Most other required libraries will get installed automatically because of dependencies. I know its silly, but this is what I usually end up doing.
-- Edit --
I've since written a couple of scripts to help manage this. The first runs pip freeze and adds the found library to a provided requirements file, the other, runs pip install, and then adds it to the requirements file.
function pipa() {
# Adds package to requirements file.
# Usage: pipa <package> <path to requirements file>
package_name=$1
requirements_file=$2
if [[ -z $requirements_file ]]
then
requirements_file='./requirements.txt'
fi
package_string=`pip freeze | grep -i $package_name`
current_requirements=`cat $requirements_file`
echo "$current_requirements\n$package_string" | LANG=C sort | uniq > $requirements_file
}
function pipia() {
# Installs package and adds to requirements file.
# Usage: pipia <package> <path to requirements file>
package_name=$1
requirements_file=$2
if [[ -z $requirements_file ]]
then
requirements_file='./requirements.txt'
fi
pip install $package_name
pipa $package_name $requirements_file
}
pipreqs solves the problem. It generates project-level requirement.txt file.
Install pipreqs: pip install pipreqs
Generate project-level requirement.txt file: pipreqs /path/to/your/project/
requirements file would be saved in /path/to/your/project/requirements.txt
If you care a lot about the cleanliness of your requirements.txt you should not only use the --no-site-packages option as already mentioned but also consider not to pipe the output of pip freeze directly to your requirements.txt. The reason for that is, that when doing a pip freeze not only packages specified by yourself show up, but also dependencies installed by these packages! It isn't necessary to keep them all in your requirements.txt as they will get installed automatically with the package that requires them...
So if you add a new package to your virtualenv you probably should just add the line for this package to your requirements.txt...
See this example:
(demo)[~]$ pip freeze
distribute==0.6.19
wsgiref==0.1.2
(demo)[~]$ pip install django-blog-zinnia
Downloading/unpacking django-blog-zinnia
Downloading django-blog-zinnia-0.9.tar.gz (523Kb): 523Kb downloaded
Running setup.py egg_info for package django-blog-zinnia
no previously-included directories found matching 'docs/api'
no previously-included directories found matching 'docs/build'
no previously-included directories found matching 'docs/coverage'
no previously-included directories found matching 'zinnia/media/zinnia/css/.sass-cache'
Downloading/unpacking BeautifulSoup>=3.2.0 (from django-blog-zinnia)
Downloading BeautifulSoup-3.2.1.tar.gz
Running setup.py egg_info for package BeautifulSoup
# truncated as it installs some more dependencies
Successfully installed django-blog-zinnia BeautifulSoup django-mptt django-tagging django-xmlrpc pyparsing
Cleaning up...
(demo)[~]$ pip freeze
BeautifulSoup==3.2.1
distribute==0.6.19
django-blog-zinnia==0.9
django-mptt==0.5.2
django-tagging==0.3.1
django-xmlrpc==0.1.3
pyparsing==1.5.6
wsgiref==0.1.2
(Though I should probably mentioned that in most cases it will not hurt that you have these dependencies there, just your file will grow and get harder to maintain.)
You can use:
pip freeze --local > requirement.txt
so only the packages installed locally in your virtualenv are listed in requirements.txt, not the globally-installed packages.
Simply,
pip3 freeze requirements.txt
then if you wanted to install all
pip3 install -r requirements.txt
It is bad to use pip freeze to create the requirements file... You should manage your dependencies manually!
I've created a script to fix this issue (I've already been in dependency conflict hell).