Compute Instance: Best practice for custom Anaconda env - azure-machine-learning-service

I'd like to use a compute instance as my develop machine.
Are there any best practices on how to handle custom Anaconda enviroments on these machines?
So far, I do it this way:
conda create --name testenv python=3
conda activate testenv
conda install ipykernel
ipython kernel install --user --name=testenv
sudo systemctl restart jupyter.service
--> Reload the JupyterHub in your browser.
Do you see any drawbacks by doing it this way? I know, some special package combinations in the standard env are lost, but I'd like to know what I've installed in my system.
Of course, one could combine it with an environment.yml.
What do you think?

Your workaround is the best option as of now. But I know that the Azure ML product group has been working on exactly this problem, but I can't make any promises as to timeline.
I share your dream of an easily configurable data science cloud development environment that allows for Git repo cloning and environment creation w/ a conda yml. We're so close especially given all the press & announcements around Visual Studio Codespaces!

Related

Can Anaconda and a more recent version of Python coexist in Windows 10?

I am taking a beginner course in Python so I downloaded and installed Anaconda on a
Windows 10 OS. It is possible to install the last version of Python, say 3.9.x or 3.10 to be run on VSCode. How do I manage to avoid conflicts between them. Can anyone tell how should I do because I have to use that text editor. Thanks in advance.
Yes, but Anaconda includes an environment management tool, Conda, and so it would be more idiomatic to use that to create a new environment, rather than installing a native, system- or user-level Python interpreter. If you are using Anaconda, then from Anaconda Command Prompt try
conda create -n py39 python=3.9
or
conda create -n py310 python=3.10
Note the argument used in the -n (or --name) is arbitrary - feel free to name environments as you'd like.

Installing Anaconda on Linux VM Instance on Google Cloud Platform

I have provisioned a VM (ubuntu-minimal-1804) on google cloud platform. I want to install anaconda3 and run jupyter notebooks on it. I lack the Computer Science/ IT background and hence tried to follow the online resources. I am finding it difficult install the anaconda3 and jupyter on the VM despite following these sources. Can anyone help me with this? I would really appreciate if anyone can provide me with step-by-step guide.
Note: These are the links that I followed but failed to install anaconda
https://www.cloudbooklet.com/how-to-install-anaconda-on-ubuntu-18-04-lts-google-cloud/
https://www.datacamp.com/community/tutorials/google-cloud-data-science
Thank you in advance
The steps that you have followed should be applicable to your Ubuntu 18.04 LTS VM (with the official image and default setup), after locating it in your instances list and clicking on the SSH button.
Despite the "minimal" images lacking some of the commonly-used utilities in Ubuntu, I could test the commands in the guide in a new VM from the ubuntu-minimal-1804-lts image family and managed to successfully install Anaconda3, except for the VSCode installation that seemed to have an outdated server connection check.
I would also recommend trying the latest installer for Anaconda3 that's available in the repo archive instead, as the one in the guide is a bit outdated:
$ curl -O https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh
$ rm -rf ~/anaconda3 # (clear previous attempted installation first, if any)
$ bash Anaconda3-2020.11-Linux-x86_64.sh
In any case, as suggested by John Hanley, feel free to comment below or edit your question with any errors that you might get.

Kernel Error in Anaconda Python Jupyter Notebook

I have started learning python and in the initial stage i am not be able to execute any code on python. While searching over the google, i found that it occurs due to kernel error and same is reflecting on the top and trust box is disabled. I have re-installed the software 2/3 times and Anti Virus program was also disabled until software gets installed properly on system. But it didn't work. I am attaching the screen shot for your reference.
I am totally new in the programming end and hence if you could explain me what exactly needs to be install step by step it would be helpful to make things done easily. There are many posts wherein answers are mentioned, but i didn't understand how those code to be executed.
Please try out by creating a new conda environment.
Create conda environment using the command :
conda create -n <env_name> -c intel python=3.6
Activate the environmemt using the command :
source activate <env_name>
Please install the required packages in this environment.
Kindly install the ipykernal using the command:
conda install ipykernel
ipython kernel install --name <env_name> --userĀ 
Select the installed ipykernal from your jupyter notebook.
Hope this helps.
Please refer the following link, https://github.com/jupyter/notebook/issues/2301

How to distribute python3 code which contains external libraries

I wrote a small script in python3 that uses numpy, matplotlib, and other libraries used by pyCharm CE in my linux machine.
I used pyCharm to code and create the virtual env.
The script works only inside pyCharm because of the dependencies.
And a friend of mine wants to use my script in a windows machine. I'm not sure if even he has python installed.
How can I run my script outside pyCharm, or how can I activate the virtual env created by pyCharm to run the script?
And
How I can create a package or something to give the script to my friend or anyone else to freely use it?
Thanks
One way of going about to ask your friend to install python3.x and pip in his system. Meanwhile you create a requirements.txt which consists of the libraries that need to be installed and their versions in this format.
dj-database-url==0.5.0
Django==2.2.5
pytz==2019.2
sqlparse==0.3.0
psycopg2>=2.7,<3.0
Then ask your friend to run pip install -r <path to requirements.txt>. This will install all the required libraries and if there is no OS based dependencies then the project should run fine.
Another way of doing it in the case of bigger project where there are OS based dependencies is to use a containerization tool such as docker. Containerization lets you run projects, in other machines, which are dependent on various packages or environments which are available/installed in your machine.
For example: Imagine I created a python based application which is dependent on multiple packages in my Debian machine. I can build a docker image using python3.x as the base and install the required packages inside the image during the build time. It is fairly simple to do so. After doing so I can push the image to docker hub which is a registry to store docker images. Do mind that the images stored here are publicly available. If you are worried about that, you can use a private AWS ECR registry to store your images. Once I have pushed the image, anyone with access to the image can pull it and spin up a container. A container is an instance of an image which can run the applications/scripts/anything that the image is built to do. In order to be able to spin up containers they will need docker installed in their machine.
This way you can share your project and make it run in anyone's machine with as little hassle as possible. They will not need anything other than docker installed in their machine. Unlike Virtual Machine docker containers are not heavy on your machine.
In your case using docker you can build an image (much like an ISO image) with python3.x as base and install all the required packages such as numpy, matplotlib and other libraries, then copy the scripts required for the project to run into the image and push it to docker hub or a private registry of your choice. Then you can give your friend an access to the image. Your friend will need Docker for Windows installed in his machine in order to be able to spin up a container using the image you provided him with. This container will have your script running as it will have all the required dependencies installed in it by you while building the image itself.
For more info on Docker: https://www.docker.com/

Downloading and installing PyBluez for a 64-bit Windows 10 PC?

I'm trying to use bluetooth with python, and I came across a module - pybluez. Right then, I tried installing it by running pip install pybluez. The package was located and downloaded, but it raised an error when running python setup.py egg_info.
I then tried to download pyBluez from this link https://pypi.python.org/pypi/PyBluez
But, it said that the Python version installed on my PC is not 2.7 ( I have 2.7.10; do I need 2.7.0 for this?) Also, this download link is for a 32-bit system, and that might be the reason it does not run on mine.
So I ask:
1. How do I fix this error?
Error in the output when I try to install pybluez using pip:
2.Does download using https://pypi.python.org/pypi/PyBluez need python 2.7.0, and a 32-bit system? If so, can someone suggest a better way for a 64-bit system?
3.Any other bluetooth module that could work as a substitute?
I have successfully built pybluez for win10x64 with python3.6
Download and install windows 10 build tools: https://www.visualstudio.com/pl/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15
Run 'Developer Command Prompt for VS' as administrator
Clone pybluez repo https://github.com/karulis/pybluez
cd to directory with repo
run python setup.py install
Happy bluetoothing
This is an "expanded solution" which supplements the other answers posted.
Bluetooth is readily supported on Linux in basically any context. Python 3 built-in socket objects work over bluetooth even. But for Windows, there are hoops to jump through. The standard solution for this is to use PyBluez. If you're really lucky, you might be able to install with just pip install PyBluez-win10. If that fails, however, the way to go is an installation via a pre-compiled "wheel".
A given wheel only works for your specific context, however, i.e. exact Python version. So, for the sake of future proofing, if you are going to need PyBluez, you should know how create a wheel from the source for yourself. It's a long, annoying process if you don't have the all the software required already and are not familiar with some parts of the process e.g. using Anaconda. So, if you are working in a team, I suggest having one person burn their time on this and then share the wheel with everyone (who are hopefully on the same version of Python!).
The following is a paraphrased version of what is posted here: https://github.com/pybluez/pybluez/issues/180 which includes the actual developer's comments and methodology.
Download and run the "Visual Studio Build Tools" installer:
For an official list of exact compilers and links to match against target Python versions, refer to: https://wiki.python.org/moin/WindowsCompilers
Here's the 2019 Build Tools link, which works with Py3.7:
https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
During the install you MUST select BOTH "Visual C++ build tools" AND "Universal Windows Platform build tools". Leave the default options alone within those (e.g. including the Windows 10 SDK).
Note: this requires 15GB of disk space, and some patience!
Install "Miniconda":
https://docs.conda.io/en/latest/miniconda.html
Select the one which matches the bit set (32 vs 64) of the destination Python version
you wish to install PyBluez into.
Clone the PyBluez source repo to a temp location (e.g. your desktop). Then, launch the terminal and change into that directory:
git clone https://github.com/pybluez/pybluez
cd pybluez
If you did NOT put conda on the system path (as the installer recommends NOT doing so), you can add it for this local CMD session per this example command:
set CONDA_DIR=%USERPROFILE%\Miniconda3
set PATH=%CONDA_DIR%\condabin;%PATH%
Create a dedicated environment to build pybluez with the desired Python version. Then, launch that. The example below uses Python 3.7 but the same steps will also work for other versions (including Py 2.x etc)
conda create -y -n pybluez python==3.7
activate pybluez
Build a wheel file. Then, leave the dedicated environment.
python setup.py install
python setup.py bdist_wheel
deactivate
Copy the wheel to your desktop. From there, you can do with it as you wish. Then, delete the pybluez conda environment and the source repo, (as you no longer need either of them).
copy .\dist\*.whl "%USERPROFILE%\Desktop"
cd..
rd /s /q "%CONDA_DIR%\envs\pybluez"
rd /s /q pybluez
Finally, you can install the wheel to a target Python instance and/or store/share it:
The name of these files and the path will vary, so define those first for your use case
set PYBLUEZ_WHEEL=%USERPROFILE%\Desktop\PyBluez-0.22-cp37-cp37m-win_amd64.whl
set PYTHON_PATH=python
Install the wheel:
%PYTHON_PATH% -m pip install "%PYBLUEZ_WHEEL%"
Confirm installation:
%PYTHON_PATH% -c "import bluetooth; print(bluetooth.__version__)"
I downloaded a Python 3.6 wheel from here (wheels for python 2.7, 3.5, 3.6, 3.7 available too).
I installed it in my virtual environment via
pip install PyBluez-0.22-cp36-cp36m-win_amd64.whl
One command solution.
pip install git+https://github.com/pybluez/pybluez.git#egg=pybluez

Resources