PyCharm and external libraries - matplotlib

I have started to use PyCharm IDE, but I was not able to determine how to manage external libraries there. For instance, PyCharm does not see matplotlib. In PyCharm's file manager, I clearly see the list of external libraries and there is no matplotlib. However, I have it installed and I know its location.
How can I add this library to PyCharm environment?

I suggest to use Python virtual environment. It is really easy with PyCharm.
PyCharm > Preferences... > Project Interpreter > Python Interpreters
Click "Create Virtual Environment" and pick your base interpreter.
Click "Install" and install any packages you need. You can also add other repositories if the default ones do not contain required libraries. Another benefit is that you can see which libraries have newer version and can be updated.

I think one way to solve a problem is to specify your interpreter in PyCharm itself via File -> Settings -> Python Interpreters
There is also a Paths tab in this setting, you need to add path to your matplotlib explicitly there. But for me there is no special path listed there. Here are my paths in this tab:
file://D:/hg_work/vefw_regression/tools/python/DLLs
file://D:/hg_work/vefw_regression/tools/python/Lib
file://D:/hg_work/vefw_regression/tools/python/Lib/lib-tk
file://D:/hg_work/vefw_regression/tools/python
file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages (my matplotlib/numpy and other stuff is here)
file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages/win32
file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages/win32/lib
file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages/pythonwin
file://D:/Users/svecovs/AppData/Roaming/JetBrains/PyCharm Community Edition 3.0.1/helpers/python-skeletons
file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages/core (added by user)

Install matplotlib and then python-tk.Pycharm will function well.It's working for me at Ubuntu 16.04.
sudo apt-get install python-tk
sudo apt-get install python-matplotlib

For Linux Users here is a solution ,
firstly write this command in the terminal ,
sudo apt-get install python-matplotlib
Now you're done you will be able to see matplotlib in File>>>settings>>project interpreter.
Image

Solve this problem by choosing system interpretator.

Related

Problem running a PyQt5 project in WSLg - no application window shows up

I am running WSL2 under Windows 10.
If I type "gedit &" into the WSL console, the Gedit application window pops up. Thus I assume that WSLg properly works.
Next, I am trying to run the following PyQt5 project:
https://github.com/rafaelpadilla/review_object_detection_metrics
However, no application window pops up this time, although no error message appears either.
First of all, I do wonder whether this could work at all with WSL!?
Appendix for additional context:
I am not using conda because of licensing issues, but a combination of pyenv + poetry instead. First I had problems with a missing library (libxcb.so), which I could solve by running "sudo apt python-pyqt5". Now everything seems to work, except from no application window being shown.
UPDATE:
I tried with "/src/pyqt-official/qtdemo/qtdemo.py" from the official PyQt Examples github repository and I observed exactly the same issue.
There is no error message. Last prompt informs me that the "xcb plugin was loaded“, then nothing happens. In particular, no window is showing up.
Some related observations:
(1) I haven't yet updated my grafics card driver to support vGPUs. However, Gedit works and opens in a separate window.
(2) Unless I do "sudo apt install python3-pyqt", I receive an error message saying that it cannot find "libxcb.so". However, I am running the code in a virtual pyenv/poetry environment, which is separate from the system python installation. I don't understand why "sudo apt install python3-pyqt" makes a difference here. Shouldn't installing "PyQt5" with poetry obtain a wheel that comes with all libraries already compiled? I don't understand how all of this is playing together.
Open Questions:
Do you think the driver issue could be an explanation? I actually cannot imagine that. I thought it is only about better performance for OpenGL applications.
Can you explain observation (2)?
What else can I do?
First of all, I do wonder whether this could work at all with WSL!?
I can't tell you if that particular application will run under WSL, but my expectation is that it will. As far as I can tell in its dependencies there doesn't seem to be any reliance on GPU compute. That, to me, would be the trickiest part to configure under WSL (but is still typically possible). However, there may be other dependencies (not covered below) that you need to get running before the application can work.
What I can confirm is that PyQt works under WSL just fine. However, keep in mind that a default Ubuntu installation under WSL is based on a non-GUI Ubuntu Server distribution, rather than standard Ubuntu (with a desktop and GUI).
This means that Ubuntu Server is often missing system level libraries needed for GUI support, which appears to be the case here.
I don't understand why "sudo apt install python3-pyqt" makes a difference here. Shouldn't installing "PyQt5" with poetry obtain a wheel that comes with all libraries already compiled?
Poetry and/or Pip manage the Python library dependencies, but those Python libraries still require the native system library dependencies. That's where sudo apt install python3-pyqt5 comes in. Under a desktop Ubuntu system, most of these libraries would already be in place. However, with Ubuntu Server/WSL, they aren't.
For reference, here's my configuration. On a freshly initialized Ubuntu 22.04 WSL2 distribution:
sudo apt update && sudo apt upgrade -y
sudo apt install python3-venv python3-pyqt5
mkdir -p src/pyqt_test
cd src/pyqt_test
python3 -m venv .venv
source .venv/bin/activate
pip install pyqt5
I was then able to create and run the following, taken from Learn Python PyQt:
import sys
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
windows = QtWidgets.QWidget()
windows.resize(500,500)
windows.move(100,100)
windows.show()
sys.exit(app.exec_())
The window displayed correctly.

Import pandas could not be resolved from source Pylance(reportMissingModuleSource)

I've been trying to use the packages pandas, numpy, matplotlib, seaborn in my "Visual Studio Code", but the program keeps showing me the following message:
"import pandas could not be resolved from source Pylance(reportMissingModuleSource)"
Previously to Visual Studio Code I installed "Anaconda" to use Jupyter, and now it says that i have the existing packages (pandas, numpy...) but keeps appearing this message that doesn't allow me to use pandas in my Visual Studio.
Anyone could help me to solve this issue?
I tried installing again all the packages to check if they didn't exist but apparently are installed all of them but in another route. I can't find how is the way to put them so the Visual Studio Code recognizes them and I can use them.
I also received similar an error on my IDE VSCode and currently using mac m1 .First we need to make sure that the python3 interpreter version from terminal version is the same with our python version selection in VSCode.
open terminal.
type 'python3'
then you will see your python version.(my python3 version is 3.9.12)
python3 version
open your IDE VSCode
open any/current folder that related to python project on IDE VSCode
Check your python version at the bottom right on IDE VSCode (in my case the python version is 3.10.64)
change or switch VSCode python version from 3.10.64 to 3.9.12 (same with your python version on your pc)
done
I also had this problem and it was because of version mismatches.
I had installed Python AND Anaconda. If anyone else has done this and gets this error, you need to uninstall both. Then install Anaconda only; Python (the compatible version) is installed as part of that process.
See https://docs.anaconda.com/anaconda/install/windows/
Also, you can click on the interpreter version at the bottom left corner of the screen (Vs.code 2022) it should show a dropdown menu with a list of the available and selected python interpreter. Click on add interpreter path and paste the path to the python interpreter with all the required modules installed and click enter. This should resolve the problem.
I re-entered the path to Python interpreter and warning disappeared. Hope that helps you.
Another way I solved this issue having followed every other installation process to the letter was deactivating Pylance. Works a (py)charm now.
I encountered this problem in VSCode under remote to WSL2 of Windows 10. The Python version is correct as interpreter (3.9.13) and the terminal in VSCode is also under the same envs (ie. VSCode ran "conda activate xx" and (xx) is shown in prompt)
Originally, I tried to install the pandas by the following command.
sudo apt-get install python3-pandas
Pandas was installed successfully as stated in the terminal but the problem is still there.
When I try to install pandas by the following command, the problem solved.
pip install pandas

which one is better in installing tensorflow

I followed the instructions on the official website to download the TensorFlow. I chose to create a virtual environment as the instruction shown for macOS. My question is that if I need to activate the virtual environment each time before I use TensorFlow?
For example, I want to use tensor flow on Jupiter notebook and that means I need to install Jupiter and other required packages like Seaborn/pandas as well on the virtual environment. However I already downloaded anaconda and basically, it has all the packages I need.
Besides, will it make a difference if I download it with conda?
Well, if you downloaded the packages (like you said TensorFlow and Seaborn) in the base Conda environment which is the default environment that anaconda provides on installation, then to use what it has, you need to run whatever program/IDE like Jupyter lab from it. So you would open Anaconda Prompt and then type in jupyter lab and it would open up a new socket and you can edit with your installed python libraries from Conda.
Otherwise in IDE's VSCode you can simply set the python interpreter to that from Conda.
However, if you install the libraries and packages you need using pip on your actual python installation not Conda, then there is no need for any activation. Everything will run right out of the box. You don't need to select the interpreter in IDE's like VSCode.
Bottom line, if you know what libraries you need and don't mind running pip install package-name every time you need a package, stick with pip.
If you don't like to that sort of 'low level' stuff then use Anaconda or Miniconda.

Chmod from IntelliJ on Windows?

I'm using PyCharm on Windows. How can I set executable bit or modify other permissions like Linux chmod? I found this only and nothing suitable in plugins but still hope there's a better solution then switching to Linux console for that purpose.
I ran into the same issue, but I wasn't very eager to install yet another plugin. If you happen to use Git, you can do it from PyCharm's terminal using the following command:
git update-index --chmod=+x path-to-your-file

How to download Keras_contrib (and other packages that is not avaliable in conda) to Pycharm?

I am quite familiar with Pycharm except 1 thing that I can't seem to figure out how to download Keras_contrib which is not availble in conda's channel and conda-forge channel which is also often used.
I have read the following article which suggest to add additional channel to conda.
"How to Install a Package in PyCharm when project interpreter is set to conda, and the package is not provided/listed by conda? 1"
but as I mentioned Keras_contrib is not provided, and I am not sure quite sure how to download it.
I managed to install Keras_contrib sucessfully to my environment which is also used by Pycharm interpreter, but for some reason, Pycharm does not recognize it.
I follow instruction given in https://github.com/keras-team/keras-contrib
which is running setup.py install
Here are the questions
By doing this Does it get install in the site_packages automatically? because I do not see it.
if I have to do it manually, how come my environment can recognize it, but Pycharm cannot.
Is there a default location in which environment and Pycharm usually look at?
because it would make sense in this case that one may recognize it while other may not.
How can I download Keras_contrib which is not avaliable in well known channel?
Is there other way to check that Pycharm Interpreter is compatible with my anaconda environment other than looking folder it is linked to?
In my case they link to the same environment, but Pycharm just cannot recognize
I just figured it out.
so Pycharm looks at site-packages of your environment.
I solved by problem that Pycharm cannot recognize the packages while anacoda env can by copy and past the Keras_contrib to the site-packages. (I still find this to be strange if any one answer to this. Feel free to comment)