Python plotting on remote server using PyCharm - python

I have started to learn Python and so far my setup has been following - Python 3.5 installation on Win10 64bit local machine with PyCharm as a great IDE. Everything works, matplotlib charts and other visual outputs display fine, debugging works, etc.
Now, I have came across some libraries which works only on Linux. I have set up Ubuntu 16.4 64bit VPS on Digital Ocean, installed Python 3.5. In PyCharm I have set up SFTP connection to remote host. Code running works, debugging works, however, I am not able to bring display output (matplotlib plots,...) to local (Win10) machine. As I am not at all familiar with Linux GUI environments (X11?), after googling I have following questions:
1) Should anything be installed on remote Linux machine? (e.g. x11 client/server/smth?)
2) Should anything be installed on local Win machine? (e.g. Xming?)
3) Should anything be configured on remote Linx machine? (e.g. X11 forwarding)
4) Should anything be configured on local Win machine PyCharm?
5) There are X11 forwarding settings in Putty and some have suggested to use those but I am not sure, should Putty session run in paraller with PyCharm and can that be avoided.
Thanks a lot!
PS - I have installed Jupyter Notebook (and latest Jupyter Lab) on remote machine and it works excellent, however I am still prefering PyCharm as primary IDE with better code completion, debugger and other perks.

Ok, after some more googling I finally managed to get this process working, hope it helps somebody:
1) on remote host (VPS, Ubuntu 16.04) I had to install X11 server, which I did by:
sudo apt-get install xorg
sudo apt-get install openbox
2) On remote host I had to make sure that X11Forwarding is enabled in /etc/ssh/sshd_config
3) On local Win10 machine I had to install Xming server and launch it with default settings.
4) On local Win10 machine I had to configure Putty to use X11 forwarding (Connection-> SSH -> X11 Forwarding) with default settings and keep connection open while running PyCharm (it seems there is no option in PyCharm to enable x11 forwarding, so putty must be running in the background)
5) On remote machine I had to check Display number (echo $DISPLAY) - this can be different for everyone. For me it was localhost:10.0
6) In PyCharm Run configuration -> Environment variables I had to add DISPLAY=localhost:10.0
After all these steps and Putty+Xming running in backgroud, I was able to execute remote code and bring graphic back to my Windows 10 PC!
PS - process is actually slow, I have to wait around 10 seconds before image is brought back to me. I am not sure why or how to speed it up. Might be another question. (reducing chipher strength and enabling compression does not help. It seems some sort of initialization problem with x11 remote and local)

Mac user should install XQuartz instead of Xming.
And another important thing: if you install xquartz via homebrew, you should relogin your macos or reboot.
As the rackpas's answer saying.

Related

Send command to MacBook Terminal from Pycharm installed on virtual Windows

Background:
Through VMWare Fusion installed on my MacBook, I have Windows installed virtually in the VMWare Fusion environment. On the Windows, I have Pycharm IDE through which I run automated python program to control bench instruments from Keysight and Techroniks. No issues.
PS- The instrument drivers are available only for Windows, thats the reason I am using Windows virtually on MacBook
Question:
From Pycharm (installed on virtual Windows), I would like to send any command (say, print Hello World) to the Terminal of the MacBook.
How to do this and what would be the command syntax (or package needed)?
There is no single package to do this.
At a minimum, your Mac host would need to run a server process. Then the VM would need to be on a host network bridge such that it is remotely addressable. Then, you can write a client that sends RPC requests to the host's server process.
At a low-level, you can use socket library, but you may want something higher level like httpserver.
Related - VMWare fusion: connecting to host's web server from guest
The other option without external dependencies would be to communicate over a file-system share.
If you want to install external software, then you can introduce a remote message queue or database.

Running Ruby, Node, Python and Docker on the new Apple Silicon architecture? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
How do you get a Ruby, Python and Node.js development environments running on Apple Silicon architecture. What about virtualization software e.g. Docker?
Programming languages such as Ruby, Node and Python should run on Apple M1 Chip but Docker is not supported as of now (They are working on it)
Docker for Mac Issue
https://github.com/docker/for-mac/issues/4733
Docker team might be working on fixing the issue as per this:
https://github.com/docker/roadmap/issues/142
My Recommendation:
Get it now only if you want to build iOS application. Since most of the people don't have the laptop right now, we might end up with a lot of other issues.
UPDATE:
This one is more appropriate answer now:
https://stackoverflow.com/a/65253659/8216911
I've tried many things and had some real trouble getting things working, but in the end, here is the simplest way I've found to get Docker running on a new Mac Silicon M1 chip.
Docker does not natively work, VirtualBox doesn't work, Parallels doesn't work, ... in the end, it goes down to using UTM to create a Virtual Machine, install Ubuntu server on it. Once you have that, you can install whatever you want on it (Docker, Node JS, Apache, PHP, MariaDB, ...).
Then you set eveything up so you can use all your favorite Mac OS tools ( Terminal, Transmit, VS Code, Safari ... ) to work, just as if you had all that on your local file system.
1 - Download Linux installation disk
Grab an ARM linux distribution. I took Ubuntu server 20.04 LTS:
https://cdimage.ubuntu.com/releases/20.04/release/ubuntu-20.04.1-live-server-arm64.iso
It's 922 MB.
I got it from here: https://ubuntu.com/download/server/arm
You can chose any linux distribution, but just make sure you get the ARM version (some distributions don't have one).
2 - Download UTM
UTM is a virtualisation software that is mainly aimed at IOs devices, but it works on Mac OS too.
https://github.com/utmapp/UTM/releases/download/v2.0.14/UTM.dmg
That one is 255 MB.
Future versions will be available from here: https://github.com/utmapp/UTM/releases/
Simply download the package, open it, and launch the application that is inside.
3 - Create your VM
Create your new VM, attach the linux installation disk to it and launch the VM following these steps here:
https://github.com/utmapp/UTM/wiki/Install-Ubuntu-ARM64-on-Apple-M1
Basically:
click Create a New VM
in the Information tab: choose a name and an icon for your VM
in the System tab:
in Hardware choose ARM64 (aarch64) architecture
give it some memory (how about 4 GB ...)
in the Drives tab:
create your main drive with New Drive, interface VirtIO and choose the size you want (I chose 20 480 MB), then click Create.
create the CD drive with New Drive, check Removable, interface USB, click Create
Save the VM
Select your shiny new VM in the sidebar and in the bottom right corner, click Browse and select your Linux installation ISO virtual disk.
You can now launch the VM, it will boot on the Linux installation CD: install Linux.
During this classic installation process, you will be asked to create a user account on the linux system (let's call it bob). When the installation is finished, shut down the VM and extract the installation disk before rebooting.
4 - Working inside your VM
When you restart the VM, you get a terminal asking you to log into Linux, using the username and password you created during installation.
You can now install Docker, openSSH-server, nodeJS, using classic apt-get commands.
5 - Working in your VM from MacOS
If you failed like to me chose the right keyboard, you might have trouble typing some special characters. The best way to work with your VM is now to work from outside of it.
Stop the VM (sudo shutdown -h now if you are already inside the shell) and go back to UTM:
Select your VM in the left side panel and click the top right button to edit the VM again :
Go to the Network tab and in front of Port Forward, click New.
You need to manually add a new port forwarding directive for each port in your VM you want to access from your Mac OS Host.
For example for SSH: in the new port forward form, simply write 22 in Guest Port and what you want in Host Port (let's say 3022).
Now you can restart your VM and in a normal Mac OS Terminal, you can log into your VM with
ssh -p 3022 bob#localhost
If you don't want to type your password each time, copy the content of ~/.ssh/id_rsa.pub (from Mac OS) inside a newly created /home/bob/.ssh/authorized_keys text file, inside the VM.
6 - copying files via sftp
Sadly, I did not manage to access the content of the VM directly with the finder. I had to use the famous FTP client Transmit.
Create a new connection with:
Protocol: SFTP
Host: localhost
User: bob
Password: [your password]
Port: 3022
(yes, the port is the same as SSH)
You can now freely explore and copy files to and from your VM.
Oh but wait ... there is more!
7 - working with VS Code on your VM
Now you can also work on your VM, from your Mac OS VS Code, installing the Remote Development extention:
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
Once the extention is installed, click on the green >< sign at the bottom left of your VS Code window and choose Remote-SSH: connect to host ...
Choose add new SSH host and type ssh -p 3022 bob#localhost
Now you can work in VS Code on a project inside your VM just as if it was in your local file system.
I do some Nuxt.js development that calls an API powered with Apache / PHP / MySQL (had to switch to MariaDB because I could not find an ARM version of MySQL that was working) that is all running in different Docker containers inside the VM using docker-compose.
Having Port Forwarded the guest 3000 port to the host 3000 port, I can browser the front end with Safari just as if it was all running natively on Mac OS.
I hope this all saves you some time.
For docker there is a technical preview out https://docs.docker.com/docker-for-mac/apple-m1/.
You can run ruby, python etc. directly on a Mac M1 by setting up a terminal that runs under Rosetta mode. Then run home brew and you can use the existing x86_64 architecture brew taps. I'm using /bin/bash as my Mac shell rather than zsh but you could adapt the below for zsh if you prefer.
Log in to your normal shell and install ARM homebrew to /opt/homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Now set up a new "Rosetta shell" terminal profile with the Shell tab Run command "env /usr/bin/arch -x86_64 /bin/bash --login".
Login again under rosetta shell and install x86_64 homebrew to /usr/local/homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Edit your ~/.bash_profile and add some code to detect if your shell is under Rosetta and if so use the /usr/local/homebrew instead of the usual /opt/homebrew
if [ "$(sysctl -n sysctl.proc_translated)" = "1" ]; then
# run under rosetta 2 with
# env /usr/bin/arch -x86_64 /bin/bash --login
#local brew_path="/usr/local/homebrew/bin"
eval $(/usr/local/bin/brew shellenv)
export PS1="i \D{%I:%M %p}:\w $ "
else
#local brew_path="/opt/homebrew/bin"
eval $(/opt/homebrew/bin/brew shellenv)
fi
Now login to your Rosetta shell and do commands like
$ brew install ruby
then you can run ruby.
I have also managed to get a vagrant virtual machine Fedora 33 for ARM running on Mac M1 under Parallels virtualisation beta. That might help with apache and php. Instructions here
https://github.com/peterdragon/packer-M1-parallels-fedora33
Seems everything will work as is...
From the event presentation they said "Existing Mac apps that have not been updated to Universal will run seamlessly with Apple’s Rosetta 2 technology."

Access Jupyter notebook/lab running on a remote windows VM?

I want to access Jupyter lab interface on my local machine browser (also running on windows) from a Jupyter server running on a remote Windows VM.
Is there any analogous technique to SSH tunneling in linux but for windows?
Thanks in advance!
EDIT:
I am not looking for remote desktop since the code autocomplete doesn't work and it's really unresponsive (and I think people can relate to other problems of coding on a remote desktop platform)
Remote Desktop would be the easiest option.
If you need a browser, windows has ssh built in, but I think it has to be activated in the Windows options

How to use opencv in a remote jupyter notebook execution?

In my local machine with macOS Mojave, I installed a virtual environment with Python 3.6, opencv package and some additional unrelated packages.
I started a very simple Jupyter Notebook that is executed with no problem, here it's the code:
import cv2
print(cv2.__version__)
my_img = cv2.imread("colibri_763_460.jpeg",1)
cv2.imshow("Original", my_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Now, I'm trying to execute the same code in a Jupyter Notebook in my remote Ubuntu machine but I can't make it work. These are the steps that I took:
I copied the image file and the Notebook ypnb file to the remote ubuntu machine.
I opened an ssh session, selected a virtualenv with the same packages than my local machine and executed the "jupyter notebook"
I opened another terminal with ssh -L 8000:localhost:8888 mpastorg#mpgubu18 for the ssh tunneling
I opened my local browser in the localhost:8000 to execute the Notebooks that I have in my remote Ubuntu machine, it works with any Notebook not involving opencv.
I tried to solve my problem using two different ways:
Installing in the ubuntu remote machine the package opencv-contrib-python-headless: when I try to use cv2.imshow, I got the error method not found
Installing in the ubuntu remote machine the package opencv-contrib-python: I got the error that kernel is dead.
Does anyone know if there's any way to execute the remote jupyter notebook and see the picture locally? it maybe would be possible a workaround to embed the picture in the browser window?
Thank you very much
Marcos Pastor
I wonder if the image is being rendered using X - which you have not explicitly enabled, in both your host machine, nor in your ssh tunnel.
On the Host machine. (Where you want to see the Image).
Enter this comment
xhost+
This now allows remote X-Hosts to send you data. As you are on a Mac - you will need to have the XQuartz package installed.
Now modify your ssh command. - so that you allow X - this is typically done using a -X flag (Or it can be placed in your .ssh/config file like this
Host *
ForwardX11 yes
ForwardX11Trusted no
XAuthLocation /opt/X11/bin/xauth
ForwardAgent yes
Compression yes
KeepAlive yes
Compression yes
If you are not using a config try the -X to start with.
Hope that helps

Pycharm, Docker and GUI

So i have downloaded openAI gym into docker. And i am running Pycharm with docker remote interpreter. Everything works fine until the code gets to the rendering part where it crashes. I know that it is caused because Docker does not support GUI.
I tried using x11 but it didnt work.
Any advice ?
Assuming you're on OSX:
Your problem is probably not related with pycharm but more with how docker tries to connect to x11.
Make sure you installed the latest version of xQuartz and allow x11 network clients. Then mount the x11 socket as a volume mount in the docker container.
This blog post has a pretty good explanation on how to do that
https://fredrikaverpil.github.io/2016/07/31/docker-for-mac-and-gui-applications/

Categories