Pyplot does not show plots in WSL (Ubuntu 18) [duplicate] - python-3.x

So it seems on ubuntu for windows (windows subsystem for linux) people are suggesting we need to use Agg backend and just save images, not show plots.
import matplotlib
matplotlib.use('Agg') # no UI backend
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.title('About as simple as it gets, folks')
#plt.show()
plt.savefig("matplotlib.png") #savefig, don't show
How could we get it to where plt.show() would actually show us an image? My current option is to override plot.show() to instead just savefig a plot-148123456.png under /mnt/c/Users/james/plots/ in windows and just have an explorer window open viewing the images.
I suppose I could host that folder and use a browser.
My goal is to be able to run simple examples like the code above without changing the code to ftp the images somewhere etc. I just want the plot to show up in a window.
Has anyone figured out a decent way to do it?

Ok, so I got it working as follows. I have Ubuntu on windows, with anaconda python 3.6 installed.
Download and install VcXsrv or Xming (X11 for Windows) from sourceforge(see edit below)
sudo apt-get update
sudo apt-get install python3.6-tk (you may have to install a different python*-tk depnding on the python version you're using)
pip install matplotlib (for matplotlib. but many other things now work too)
export DISPLAY=localhost:0.0 (add to ~/.bashrc to make permanent. see WSL2 below)
Anyways, after all that, this code running in ubuntu on wsl worked as is:
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.title('About as simple as it gets, folks')
plt.show()
result:
Maybe this is better done through a Jupyter notebook or something, but it's nice to have basic command-line python matplotlib functionality in Ubuntu for Windows on Subsystem for Linux, and this makes many other gui apps work too.
For example you can install xeyes, and it will say to install x11-apps and installing that will install GTK which a lot of GUI apps use. But the point is once you have your DISPLAY set correctly, and your x server on windows, then most things that would work on a native ubuntu will work for the WSL.
Edit 2019-09-04 : Today I was having issues with 'unable to get screen resources' after upgrading some libraries. So I installed VcXsrv and used that instead of Xming. Just install from https://sourceforge.net/projects/vcxsrv/ and run xlaunch.exe, select multiple windows, next next next ok. Then everything worked.
Edit for WSL 2 users 2020-06-23
WSL2 (currently insider fast ring) has GPU/docker support so worth upgrade. However it runs in vm. For WSL 2, follow same steps 1-4 then:
the ip is not localhost. it's in resolv.conf so run this instead (and include in ~/.bashrc):
export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0
Now double-check firewall: Windows Security -> Firewall & network protection -> Allow an app through firewall -> make sure VcXsrv has both public and private checked. (When Launching xlaunch first time, you might get a prompt to allow through firewall. This works too. Also, if VcXsrv is not in list of apps, you can manually add it, eg from 'C:\program files\vcxsrv\vcxsrv.exe')
Launch VcXsrv with "Disable access control" ticked
Note: a few WSL2 users got error like couldn't connect to display "172.x.x.x:0". If that's you try to check the IP address stored in DISPLAY with this command: echo $DISPLAY. If the showed IP seems to be wrong (i.e. "8.8.8.8" or another not working IP address) you need to change the code in ~/.bashrc showed in the point 5 to something that will get your instance's ip address. One user said this worked: export DISPLAY=$(ifconfig | grep inet | awk '{print $2}' | head -n 1 | awk '{print $0":0"}'). However for some others it did not work. YMMV, but just find your IP and use if for DISPLAY. For most WSL2 users, the command in #5 works.
Edit for Windows 11 : if MS convinced you to throw out your old computer and buy one with a TPM and so you got Windows 11, you get GUI for free. I hope they add upgrade path to do that on Windows 10 because Win10 will be like XP and last a long time since MS decided you need recent computer even though Win11 would work fine on old computers.

Plots are also viewable on WSL using Visual Studio Code, which as of the June 2019 release, includes a "Plot Viewer".
In a regular .py file, inserting a comment string #%% marks the code as a Jupyter (IPython) cell and a code lens shows options to Run Cell. In addition, right-clicking inside a Python file includes the option:
Run Current File in Python Interactive Window
From the VS Code June 2019 release:
The June 2019 update included a brand-new Plot Viewer that can be used
to manipulate any image plots, such as the popular matplotlib plots.
You can try it out by double-clicking on the plots or clicking on the
“expand image” button that is displayed when you hover over plot
images in the Python Interactive Window:
With the plot viewer, you can pan, zoom in/out, navigate through plots
in the current session, and export plots to PDF, SVG, or PNG formats.

For WSL2 using Ubuntu Focal Fossa release, I downloaded and installed VcXsrv on Windows. I use this configuration:
I don't know for Native OpenGL but it seems important to disable access control.
Now, you need to export the env variable DISPLAY in WSL.
I found the correct address in /etc/resolv.conf, but the one found in the ifconfig result isn't. So the following command doesn't work for me:
export DISPLAY=$(ifconfig | grep inet | awk '{print $2}' | head -n 1 | awk '{print $0":0"}')
That IP address can also be found in the command ipconfig into CMD.exe command context. Search for vEthernet (WSL), that should be the one.
Now, you can test that everything is working by simply executing xcalc in your WSL environnement. If xcalc is not present, install it:
sudo apt-get update && sudo apt-get install x11-apps
xcalc command should open a application looking like this on Windows:
If it is working that means that the connection to your X-server is possible but you maybe need to install some extra package for Python like:
sudo apt-get install python3.x-tk
Change .x according to your python version.

To get matplotlib to work with GTKAgg on Bash on Ubuntu on Windows, I:
installed VcXsrv under Windows (but things should work just the same with Xming)
set DISPLAY as noted above [export DISPLAY=localhost:0.0 (add to ~/.bashrc to make permanent)]
executed sudo pip uninstall matplotlib
followed by sudo apt install python-matplotlib
updated matplotlibrc to read backend : GTKAgg (rather than backend : agg)
I also ran sudo apt-get install python-gtk2-dev, but this may not be necessary.
Uninstalling the pip-installed matplotlib and reinstalling it via apt appear to be necessary because pip does not include the C extensions needed to run GTK, but the apt version does.

With Windows 11 22000, Linux GUI apps are officially supported out of the box provided pre-requisites are met. No twaeks, No hacks, No firewall changes etc.
Pre-Requisites:
Windows 11 Build 22000 or higher
Installed driver for vGPU (Intel/Nvidia/AMD)
Then run the commands
wsl --update
wsl --shutdown
Done !!
Official Source : https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps

In my case (Windows 10, WSL2, Ubuntu 20.04 with miniconda3 and virtual environment where I installed all the required Python 3.6 packages using conda command, Windows-based Visual Studio Code with 'Python' and 'Remote - WSL' extensions) I installed VcXsrv under Windows, and added
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
to .bashrc file in Ubuntu. Also, before running Python code from WSL, we have to launch XLaunch and select 'Disable access control' (I left 'Native opengl' checked as well). In project folder, do not name your Python file as matplotlib.py (some related issues are reported here).

In two seperate instances (wsl1 & wls2 with ubuntu 20.04) while using PyQt5 I was missing several libxcb libraries (e.g. libxcb-icccm4) which was not printed when trying to plot. I used export QT_DEBUG_PLUGINS=1 to find out which ones and then simply installed them. Basically the steps here.

had similar problem so simply installing the supported gpu driver solved my problem. Check this out!

I found the best approach is to install Jupyter on Windows Subsystem for Linux (WSL) by following
sudo apt update && upgrade
sudo apt install python3 python3-pip ipython3
Now you can install matplotlib
pip3 install matplotlib
And Jupyter Notebook
pip3 install jupyter
Check this link if you need more info Python setup on the Windows subsystem for Linux (WSL)

Related

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

Trying to use bash on Windows and got no installed distributions message

I am trying to use bash on Windows 10, but I'm getting this message when tried to run bash:
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Windows Store:
https://aka.ms/wslstore Press any key to continue...
When I go to that url which opens the Windows Store app, there no sign of any Linux distribution there.
My windows version is(as in my right bottom corner of the screen):
Windows 10 Enterprise Insider Preview. Evaluation copy.Build
16215.rs_prerelease.170603-1840
I follow the instructions in this guide Installation Guide and also was watching this video Editing code and files on Windows Subsystem for Linux on Windows 10 from Scott Hanselman, but they didn't get the message of no installed distribution.
Any Help?
When the Windows Store opened, there was no Distro to choose, then I found this command lxrun /install and worked for me as well.
You will get something like this as an output:
C:\WINDOWS\system32>lxrun /install
Warning: lxrun.exe is only used to configure the legacy Windows Subsystem for Linux distribution.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore
This will install Ubuntu on Windows, distributed by Canonical and licensed under its terms available here:
https://aka.ms/uowterms
Type "y" to continue: y
Downloading from the Microsoft Store... 100%
Extracting filesystem, this will take a few minutes...
Would you like to set the Ubuntu locale to match the Windows locale (en-FI)?
The default locale is en_US.
Type "y" to continue: y
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: <you type your login here>
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Installation successful!
Documentation is available at: https://aka.ms/wsldocs
I'm getting a similar bug after trying to uninstall and reinstall.
For me I had to open a cmd prompt as administrator and run lxrun /install
I get this when I have recently rebooted. If I wait 5 minutes, the problem fixes itself !
The top answers written for this question are more than enough. I just had trouble following them because lxrun command has been depreceated, so I get the error
'lxrun' is not recognized as an internal or external command, operable
program or batch file.
when I try to run this command with cmd.
It has been replaced with wsl command. You can get more info on this issue here - https://github.com/MicrosoftDocs/WSL/issues/425
When you run wsl /install, there is a chance you may still get the error that you had earlier posted in your question. In that case, simply go to the link https://aka.ms/wslstore as you had gone earlier. If you don't see anything coming up, simply search for Ubuntu and install the same. (If you search with the term wsl though, you will get to see other Linux flavors too and then you can download any of your choice)
It seems that the link given in the command doesn't work. Here's the actual link to the microsoft store for Ubuntu.
https://www.microsoft.com/en-nz/store/p/ubuntu/9nblggh4msv6?rtc=1
You have to go to https://aka.ms/wslstore this link and download ubuntu on windows. After that you can use bash on windows.
If you have any problems with running lxrun /install (for example on ltsb Windows version) try manual mode.
First, go to the folder with downloaded .appx file and run following commands (change filename if needed):
Rename-Item ~/Ubuntu.appx ~/Ubuntu.zip
Expand-Archive ~/Ubuntu.zip ~/Ubuntu
After finishing cd into new folder and run ubuntu.exe file. That's it.
If you get this error after installing a distribution using the windows store, and WSL was working previously, you may need to make sure that the LxssManager service is running, since it often stops after a Windows update or a reboot.
Go to services.msc, and search for LxssManager and start it; if it is running already, restart it.
For everyone who is getting
'lxrun' is not recognized as an internal or external command,
operable program or batch file.
or
Windows Subsystem for Linux has no installed distributions.
Distributions can be installed by visiting the Microsoft Store:
https://aka.ms/wslstore
Open microsoft store, install 'Ubuntu' then open the app. This will install ubuntu and later you can use wsl command since lxrun is deprecated
Go to add or remove programs
Install Windows subsystem for Linux
Go to https://aka.ms/wslstore, which will take you to the Microsoft Store
Select and install a Linux distribution
lxrun /install
Works on a Administrator Command Prompt for Windows 10 Professional, Version 1803 Build 17134.165
This installs GNU/Linux by default whereas there is an option to select between:
Ubuntu
openSUSE Leap 42
SUSE Linux Enterprise
Debian GNU/Linux
Kali Linux
If the given link (https://aka.ms/wslstore) works, it openes the windows store for me with an error saying something is wrong on their side and to try again later.
It's actually easier to solve this problem that other solutions listed here. If you run wslconfig /l and if the output is:
Windows Subsystem for Linux Distributions:
Ubuntu (Default)
Just run wslconfig /s Ubuntu to set Ubuntu as default again. It should start working now.
Edit:
I've also found that if this problem occurs on a fresh boot, then you just wait for a few minutes (10 minutes max) and this error automatically disappears.
Edit 2:
I've also found that this error is sometimes also due to the corresponding service not running. Run CMD as administrator and run
net start LxssManager
For running bash on windows ubuntu is required to be installed.
As you've already added bash from programs and features, now you need to install Ubuntu. Contrary to what is seen in most of the installation guides on web, it does not gets installed by running 'bash.exe'.
You can simply go to Microsoft store in search for 'Bash' or 'Ubuntu'and install Ubuntu 18 LTS from there.
After installation you'll be able to use the terminal and all its commands.
Run the bash command in git bash windows. It worked !!
As of 2022, New Linux distributions are available for Windows 10 as well as Windows 11 like Kali Linux and Ubuntu. Both available from Microsoft Store. Someone watching this question now can visit Microsoft Store to Download them..
I had this same issue. But when you go to the windows store you can search for ubuntu and then install the ubuntu app and it works. I think most of the tutorials on the net are from the beta version and have afterwards never been updated.
https://insights.ubuntu.com/2017/07/11/windows-10-loves-ubuntu-loveislove/
Note: This is also old. You do not need to be on the insider builds. I'm not and it worked.
The only thing that worked for me is described here https://learn.microsoft.com/en-us/windows/wsl/install-manual#downloading-distros
https://aka.ms/wsl-ubuntu-1804
manually install it or run Add-AppxPackage.\.appx from PowerShell
The link to the store appears to have a region lock in it, resulting in errors for many visitors.
However there are different Ubuntu distributions to be downloaded. See image below, image is however in Dutch but it will show results.
So pick a version you desire and it will result in a working bash.
The actual answer to the question query is: The user exists with Ubuntu already installed. But WSL command does not find anything in CMD.exe "Command Line" "System does not find distribution."
You need to start the below WSL command from Windows Start Menu. And then the old Linux System will show up on WSL in the command line as found.
If this doesn't work for you? Just start up PowerShell with Administrator and:
WSL --help
WSL "only this command, will start the Linux default distro selected"
You can then start up using this command with CMD.exe Administrator in Windows:
lxrunoffline l "This will now list all your distros"
With an option to remove old distros copied to Windows folders are with perhaps Ubuntu18.04 such way that you will have to use Linux to remove older folders, do not try to copy or edit files in a distro with Windows Apps. You risk integrity problems as well as many errors followed by huge processing time. Use folder /mnt to find your drive with Linux and use commands there to further finish your work as perhaps copying the home directory into a new distro.
My solution to move "not copy" my distro then was: "to give space for C:"
lxrunoffline m -n Ubuntu-18.04 -d d:\wslinstalled\Ubuntu-18.04 "remember folder names"
"Remember folder name such as Ubuntu-18.04 for a specific movement. Unless you will overwrite everything on that folder name with also the lxrunoffline files and you risk losing older copies if you use one folder name. You might end up with a strange name to your project if you just use one directory."
Lxrunoffline has several other commands if you need help just run:
lxrunoffline
like beginner_ said in his answer you need to go to the store and look for the distros you want to install.
Please see the following link to understand what has changed and what you can excpect or what distros you can look for(the list is outdated so just try to find an updated list or just try your luck).
I am running on my machine without the developer mode Ubuntu, OpenSuse and Kali.
Access to Microsoft Store is blocked by my company. For me following worked in PowerShell (admin) -
lxrun /install
Go to cmd, and then run the following command:
lxrun /install
Typing lxrun /install in elevated command prompt works....
The solution to the error "WSL 2 installation is incomplete",
Execute the following steps:
wsl --install -d Ubuntu ## lxrun is no more, its now replaced with wsl,
enter image description here
wsl
enter image description here

QXcbConnection: Could not connect to display Aborted, when installing QT on linux

I am trying to install Qt on a Linux machine remotely from a Windows machine using PuTTY.
When I run the command to install Qt on Linux I get the following error:
~/QT# ./qt-unified-linux-x64-2.0.4-online.run
QXcbConnection: Could not connect to display
Aborted
Please suggest any workaround.
You can use the software repository of that Linux distribution.
For example, if it's Debian or Ubuntu:
sudo apt-get install qtbase5-dev
But if you really want to use the installer (usually, when specific Qt version is needed), then try one of the options:
run an X server on that machine
use the --script option of the online installer (you'll have to write a script like here: https://stackoverflow.com/a/34032216/4742108), it will probably need UI anyways
see if the offline installer has an option to run without UI
refer to here: https://community.nxp.com/message/532966
maybe use the cmd "export DISPLAY=:0" and it works
Try to connect with ssh to the host machine using -X to enable X11 display:
ssh <username>#<ip> -X
aqtinstall is a good option: https://github.com/miurahr/aqtinstall
It's a simple command line tool to download and install any Qt version. It's a fork of my old qli-installer script.

Import of excel in odoo on Ubuntu 14.04 - not working

When I tried to import an excel file in odoo from Windows it worked perfectly. But when tried this from Ubuntu machine it didn't work. It showed me this error
"import preview failed due to: Unable to load "xlsx" file requires Python module "xlrd >= 0.8".
Here's the screen shot
For Odoo 10, you need to install XLRD which is version 1.0.0 currently.
sudo -H pip install xlrd
The -H will take care of any error messages regarding the user environment.
Then depending on your system, you MUST restart your odoo instance, or it will not recognize that XLRD is installed.
Hope it helps. It just worked for me with Odoo 10 on Ubuntu 16.04
The error is saying that you need a python library "xlrd" in order to load this xlsx file. So make sure that you have installed this python library in your openerp ubuntu machine.
There's another way mentioned in odoo forum how you can installed it. Here it is
First you have to download the package from:
pypi.python.org/pypi/xlrd/0.9.2
Find the folder "xlrd" inside the download, copy it to "OpenERP\Server\"
Restart your server.

Android Studio not correctly rendering font on Ubuntu

Below is the picture of Android Studio when I first installed it:
I'm using Ubuntu 12.04 with Oracle Java 7. But the fonts are looking very ugly. They are not looking like they look when I see them on eclipse.
Earlier when I installed NetBeans, I had same problem too.
There actually is a solution. You need to install JDK font fix as follows:
sudo add-apt-repository ppa:no1wantdthisname/openjdk-fontfix
sudo apt-get update
sudo apt-get install openjdk-7-jdk
Then, open studio.vmoptions and optionally studio64.vmoptions in your android-studio/bin directory, and add following lines to both of them (the first one might be already there):
-Dawt.useSystemAAFontSettings=on
-Dswing.aatext=true
-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
After you reboot, the font rendering is just fine. To get the most Eclipse-like experience, go to File, Settings, Editor, Colors & Fonts, Font. Save the current scheme as a new one, and change the font to "Monospaced" with size of 14.
I've tried several suggested tweaks, tried using FontFix Patched JDK, FontForge, and editing studio.vmoptions; though some of these could show some improvement, it does not come close to the font rendering quality of the non-swing apps like eclipse.
I've found this to be the easiest and cleanest solution:
rm -r ~/.AndroidStudioBeta
If you have installed openjdk-fontfix, or made changes to studio.vmoptions, it is better you revert back those changes to their defaults.
sudo add-apt-repository ppa:no1wantdthisname/openjdk-fontfix
sudo apt-get update
sudo apt-get install ppa-purge
sudo ppa-purge ppa:no1wantdthisname/openjdk-fontfix
Remove all custom-added JAVA environment variables ($JAVA_HOME, $PATH:$HOME/bin:$JAVA_HOME/bin). Check in files, /etc/profile, ~/.profile, ~/.pam_environment
Install the latest Oracle Java via launchpad ppa
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
This ppa installer will usually do more than what a manual JDK configuration will do.
[]
Monospaced fonts like 'Inconsolata' and 'Source Code Pro' works best for me.
You do not need to install OpenJDK or the above-mentioned fix .deb for correct font rendering. Simply launch the Studio with:
_JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=lcd -Dsun.java2d.xrender=true' path/to/studio.sh
.. and fonts should render right under Ubuntu with Oracle's JDK 7. Looks even better when you change theme to GTK+ under File -> Settings -> Appearance.
In studio.sh, find this line at the bottom of the file:
eval "$JDK/bin/java" $ALL_JVM_ARGS -Dawt.useSystemAAFontSettings=lcd -Djb.restart.code=88 $MAIN_CLASS_NAME "$#"
and change it to
eval "$JDK/bin/java" $ALL_JVM_ARGS -Dawt.useSystemAAFontSettings=on -Djb.restart.code=88 $MAIN_CLASS_NAME "$#"
This means changing the parameter
-Dawt.useSystemAAFontSettings=lcd (if present)
to
-Dawt.useSystemAAFontSettings=on
Or simply add this param if you don't have it.
What you should do is configure the fonts in the settings as follows:
File > Settings > Editor > Colors & Fonts > Font
In that screen then you save a new scheme clicking in Save as, and putting a name on it, lets say "Custom".
Then below you'll find all the settings you need, you can tweak the font family and the size as well.
Android Studio 1.2 Preview 1 has been released a few hours ago (Mar 9th 2015):
http://tools.android.com/recent/androidstudio12preview1
It also includes several really important fixes that have been requested by Android Studio users, such as high density (retina) support for Windows and Linux.
It is based on IntelliJ IDEA 14.1, and according to the IntelliJ release notes, includes "The HiDPI support for Windows/Linux (scaled icons/font-size, no blur)".
However, I tried this on my machine (Ubuntu 14.10), and could not see any improvements. Maybe someone else has information on how to make it work?

Resources