After a couple years of trying different things, we finally got PyCharm to work with our ckan/Vagrant VM environment.
We tried numerous times trying to get a local instance of PyCharm to talk to our guest Vagrant VM, but that seemed quite fragile and confusing for the developers.
Then someone on our team said something to the effect of "Why don't we just install PyCharm on the Vagrant VM and then use x11 forwarding to see the user interface?"
Seemed like a good idea to try and it has been working great for us. We get all the benefits of an IDE and debugging to boot. Yay!
Here is how we did it. You will have to understand your particular environment and change what you see below to work for what you're doing. You will also need to take care of your own licensing of PyCharm!
VagrantFile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
# apache port
config.vm.network "forwarded_port", guest: 5000, host: 5000, auto_correct: false
# database port
config.vm.network "forwarded_port", guest: 5432, host: 65432, auto_correct: false
# solr port
config.vm.network "forwarded_port", guest: 8080, host: 8080, auto_correct: false
# For PyCharm
config.ssh.forward_agent = true
config.ssh.forward_x11 = true
# Install PyCharm IDE via shell script
config.vm.provision "shell", path: "install_pycharm.sh"
end
install_pycharm.sh
#!/bin/sh -e
set -x
cd /tmp
wget https://download.jetbrains.com/python/pycharm-professional-2017.3.1.tar.gz
tar -xvzf pycharm-professional-2017.3.1.tar.gz -C /tmp/
cp -r /tmp/pycharm-2017.3.1 /opt/pycharm
ln -s /opt/pycharm/bin/pycharm.sh /usr/local/bin/pycharm
ln -s /opt/pycharm/bin/inspect.sh /usr/local/bin/inspect
yum -y groupinstall "X Window System"
# Copy .Xauthority file from vagrant to ckan home
cp /vagrant/.Xauthority /usr/lib/ckan
chown ckan:ckan /usr/lib/ckan/.Xauthority
echo "==========================================="
echo "PyCharm will be installed in your Vagrant instance, but...."
echo "now you must run some manual steps to get PyCharm working:"
echo ""
echo " ssh into vagrant"
echo " This ssh will create your /home/vagrant/.Xauthority file, which you need to see the PyCharm GUI."
echo " Then you will need to copy this .Xauthority file to the ckan user to run PyCharm as ckan."
echo ""
echo " sudo cp /home/vagrant/.Xauthority /usr/lib/ckan"
echo " sudo chown ckan:ckan /usr/lib/ckan/.Xauthority"
echo " Set the DISPLAY variable for ckan user as it is set for vagrant when you do echo $DISPLAY: "
echo " export DISPLAY=localhost:11.0 "
echo " To start PyCharm run"
echo " pycharm "