Installing package on MS Azure when PIP doesnt work - python

I'm trying to install this https://github.com/mrjbq7/ta-lib package on MS Azure Jupyter notebook environment. In my local anaconda environment, this all worked well.
PIP produces the first error that is described in the troubleshooting section, but I dont understand the solution.
Next, I tried the terminal on the azure project site, but when I try to load the tar file with wget -c url, I get denied permission.
I can upload the tar file into the project folder but then I have no clue how to find the file via the terminal.
Is there another way I can try?

There is not gcc distribution and sudo permission in MS Jupyter notebook, so you will get the error as the figure below when tried to install TA-Lib via pip, because there is not its pre-compiled wheel file for installation in its PyPI page and the talib Python package requires gcc for compiling the TA-Lib source codes in C.
So the solution is to compile and package the talib library as a wheel file from source code manually, then to upload and install it with its dependencies to Microsoft Azure Notebook, finally you can make the sample code works as the figure below.
Here is my steps in details, I did it in the WSL of my local Windows machine. You can try to do the same in a Linux machine
To create a new directory and init it with virtualenv in Python 3.6
Follow the README.md content of mrjbq7/ta-lib to install the TA-Lib C source codes as the dependencies of TA-Lib Python package. It required gcc, make installed in Linux first.
Download the source codes of mrjbq7/ta-lib from its releases page, then to decompress and compile it as the commands below.
$ tar -xzf TA_Lib-0.4.17.tar.gz
$ cd ta-lib-TA_Lib-0.4.17
$ pip install numpy
$ make
$ pip wheel --wheel-dir=talib ta-lib
$ cd talib
After do Step 3 successfully, there is a file named TA_Lib-0.4.17-cp36-cp36m-linux_x86_64.whl in the talib directory, as the figure below.
IMPORTANT: TA-Lib requires a runtime lib named libta_lib.so.0 compiled from Step 3, that you can find it in the path /usr/lib and its real file be named libta_lib.so.0.0.0, so you need to copy libta_lib.so.0.0.0 and rename it with libta_lib.so.0.
Upload the files TA_Lib-0.4.17-cp36-cp36m-linux_x86_64.whl and libta_lib.so.0 of Step 4 & 5 to your project in MS Azure Notebook, as the figure below.
Finally, you can install TA-Lib from your own wheel file and run it successfully.

thanks for the extensive answer. After some back and forth i managed to compile something that looks similar to your wheel file. I used the win10 ubuntu terminal and that had its own issue with all sorts of dependencies missing by default.
Anyway it looks now like i compiled the .whl file under python 2.7 which the Azure environment doesn't accept, although im pretty sure that i upgraded the ubuntu python version to 3.6
!pip install TA_Lib-0.4.17-cp27-cp27mu-linux_x86_64.whl
ERROR: TA_Lib-0.4.17-cp27-cp27mu-linux_x86_64.whl is not a supported wheel on this platform.
Since i have to probably repeat the process, some detail questions:
1) What do I need the virtualenv for in step one? My ubuntu distro should already be setup with python right?
2) Do i need step 2 and 3? to my untrained eye it looks like step 3 is just step 2 with and updated tar file.

Related

Install PyQt5.15.4 from tar.gz file

I'm trying to install PyQt5.15.4 on a remote desktop that is not connected to internet (Anaconda distribution and PyCharm installed), hence I downloaded the tar.gz files from https://pypi.org/project/PyQt5/#files and tried to use this solution : Python import library from tar.gz? (it worked for other libraries I had to install such as python-docx). The problem is that there is no setup.py file. There is a configure.py file (I imagine it roughly do the same job), so I tried in cmd :
python configure.py install --prefix=<full path folder I used for other libraries I needed>
but I get:
Usage: python configure.py [opts] [name=value] [name+=value]
configure.py: error: no such option: --prefix
Do you have a tip ?
Download PyQT5 from here. https://www.riverbankcomputing.com/pypi/packages/PyQt5/PyQt5-5.15.5.dev2108100905.tar.gz#md5=b39c03d821123c37715daffb0c1c3bb1
This will download tar.gz fie. open the terminal, CD through the relative path, paste the command here.
pip install PyQt5-5.15.5.dev2108100905.tar.gz
if you have your own tar.gz. Then use the name of that file, which will install automatically.
pip install yourfile.tar.gz
Please let me know if that works

How do I run this python script?

I'm new to python, and I was wondering if you could help me run a python script. I'm trying to run a script called PunchBox from Github: https://github.com/psav/punchbox. So far, I have Python 3.9.5 and Git Bash.
In the GitHub page, it says:
To install, clone the repo, cd into it and then execute the following:
virtualenv -p python2 .pb2
source .pb2/bin/activate
pip install -U pip
pip install .
What does this mean exactly? Where do I run this code?
So far, I tried downloading the zip file from GitHub, installing Python 3.5.9, using cmd, finding the directory with cd, and running that code; but got an error:
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name punchbox was given, but was not able to be found.
error in punchbox setup command: Error parsing C:\Users\Mi\Downloads\punchbox-master\punchbox-master\setup.cfg: Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name punchbox was given, but was not able to be found.
There's also a requirements.txt that lists additional scripts needed:
pre-commit
click
mido
pbr
PyYAML
svgwrite
Do these install automatically upon running the script for the first time?
I'm a little confused why I'm getting an error. Do you know what I'm doing wrong?
Thank you so much!
Giovanni
I assume you are new to programming. You have to write these lines in a terminal.
On Windows, it is Command Prompt or PowerShell Applications (latter preferred). On macOS, it is terminal
Copy all these lines at once, and paste them to your preferred terminal. The terminal will automatically run these one after the another.
FYI: Venv is a python package to create a virtual environment. The preceding commands set up the environment. Now install the required dependencies using this command instead of the last command (pip install .)
pip install -r requirements.txt
Based on your comment, it looks like you don't have virtualenv installed in your system. You may install it using the command pip install virtualenv.
Now, as you are using a Windows machine, you may open a Command Prompt or Windows PowerShell window and navigate to the directory where your cloned project resides.
Now, execute the following commands.
virtualenv -p python2 .pb2
.pb2\Scripts\activate.bat
pip install -U pip
pip install -r requirements.txt
Once you are done working in your virtual environment (which is named .pb2), you may close it by executing deactivate command.
#Giovanni T.
See, as far as you have installed Python and also downloaded the GitHub Repository as a zip file.
pip install -r requirements.txt
Just run this command.
Please make sure that the directory is pointing to the folder where this requirements.txt file is stored.

How to install a custom libarry in Jupyter notebook of GCP?

I am developing a Python library and I need to make it available from GCP Notebook.
Is it possible? How?
Details:
I use Pipenv to manage my library dependencies. Currently my library source code exists in local and in a private git repository. So it is not in PyPI.
My code has multiple module files in nested directories.
My library's dependencies exist in PyPI.
Using Pipenv, the dependencies are described in Pipefile.
This is the type of my Jupyter VM instance : https://cloud.google.com/deep-learning-vm
And this is some interesting structure I could find using SSH from Google console :
$ ls /opt/deeplearning/
bin binaries deps jupyter metadata proxy-agent-config.json restriction src workspace
I envisage to install my library (using pip or something else) to be able to import its modules from the notebooks.
I need that all the dependencies of my library to be installed when installing the library.
If the Python Packages Index is public, I don't want to publish my library in it being proprietary.
Thank you.
What I understood from your question is: you are writing your own python module, which depends on many third-part python packages (can be installed with pip).
In this situation, I would probably do a pip freeze on the actual environment where the module loads everything perfectly.
pip freeze > requirements.txt (It will create a requirements.txt file with all the dependency modules/libraries)
Now, once in the jupyter notebook, you can use the following command to first install all the requirements.
(Run the following in the notebook code cell)
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install -r requirements.txt

How to install Python packages from python3-apt in PyCharm on Windows?

I'm on Windows and want to use the Python package apt_pkg in PyCharm.
On Linux I get the package by doing sudo apt-get install python3-apt but how to install apt_pkg on Windows?
There is no such package on PyPI.
There is no way to run apt-get in Windows; the package format and the supporting infrastructure is very explicitly Debian-specific.
Not quite what you're looking for, but it's possible to use apt-offline on Windows to download the packages. However, you still need a Linux box to generate the sig file.
For example:
python apt-offline set vim-offline.sig --install-packages vim
Will not work:
ERROR: This argument is supported only on Unix like systems with apt installed
However, if you run that command on Linux first, the following command should work on Windows:
python apt-offline get vim-offline.sig -d vim
apt-offline source is available here:
https://github.com/rickysarraf/apt-offline
To build it, simply run:
python setup.py build
python setup.py install
I got it to run with Python 3.8.2 on Windows 10.
Note: in the end of the day, you're just downloading a .deb package and it is simply an ar file containing a tarball and can be extracted with tools like 7-zip. However, if it contains a Linux binary (vim example), there isn't much you can do with it on Windows.
One can use chocolatey the equivalent for windows.
https://chocolatey.org/install
add it to the windows PATH environment
C:\ProgramData\chocolatey\bin
Restart python or anaconda. And is ready to use.
To install packages inside a .py script or a Jupiter notebook, use the syntax below
!choco install [package name]

How to use gfx module in python

I'm trying to use the gfx module for python (from here: http://www.swftools.org/gfx_tutorial.html). But when I do python setup.py build I get an error:
ImportError: cannot import name CompileError
I just need to open a gfx file.. (Its part of the pythonchallenge.com)
How can I do it?
I'm working on linux mint 64bit
enter code here Not sure how stable this is but there seems to be a lot of issues installing 0.9.2 on ubuntu:
wget http://www.swftools.org/swftools-2013-04-09-1007.tar.gz
tar -xzvf swftools-2013-04-09-1007.tar.gz
cd swftools-2013-04-09-1007/
./configure
make
sudo make install
sudo cp lib/python/*.so /usr/lib/python2.7/site-packages/
That should compile and install on ubuntu.
Then python -c 'import gfx' should work.
I had a look at the setup.py script and it seems it is using CompileError from distutils which is now depreciated, I replaced it with from distutils.core import CCompilerError
Running python setup.py runs after changing but complains about various errors in relation to jpeg and PIL._imaging.so so I have included an instuctions.txt in the file which has instructions on how to setup the required packages and symlinks etc...
I also had to add the lib/art directory from swftools on github and add it to the lib directory.
It runs and installs on ubuntu 14.04 but should work on mint also.
The updated package is here
download
http://www.swftools.org/download.html
You can build the Python module using setup.py
You can build it "manually" by using make
To do the former, all that should be required is
python setup.py build
python setup.py install
This is the preferred way. If the above gives you any trouble or you prefer make, the following will also create the Python module:
./configure
make
# substitute the following path with your correct python
installation:
cp lib/python/*.so /usr/lib/python2.4/site-packages/
You can test whether the python module was properly installed by doing
python -c 'import gfx'

Categories

Resources