Installing/Using Pillow on Python 3.6 and Visual Studio - python

Alright, I need some pointers. I am missing something. I am trying to use Pillow through Python 3.6. The platform I use is Visual Studio 2017. I can't get it to work.
I downloaded Pillow from this website:
https://pypi.org/project/Pillow/
And ran the installer.
According to my research, I need pip to install it; which comes built-in python 3.6. I have seen sign that it is actually installed through my module in visual studio (pip 9.0.3). I simply need to use the following line:
from pip.commands import install
and also tried
import pip
Now, according to this:
https://pillow.readthedocs.io/en/5.2.x/installation.html
All I have to do is
pip install Pillow
Though other sites indicate that PIL is still being used. I have tried both without success. Pillow is not recognized and a error comes in: invalid syntax.
I am clearly doing something wrong. I consulted some youtube tutorial; they all skip that part. They download then go straight to their coding platform and it works.
I can only guess I have additional steps to do with Visual Studio.
Also... The location of my files might be out of whack due to IT security on my work laptop. Could that be an issue?

You can do the following:
python -m pip install pillow
No need to downloade Pillow from the website.
After that, to use it you can do:
import PIL

Thanks for the feedback. I played with Visual Studio some more; there is a way of getting it straight from the menu.
I opened a Python 3.6 project/solution. On the "Python Environment" node in the solution explorer, I right clicked and created a virtual Python environment.
Then I right clicked on the virtual environment and selected "Install Python Package...".
You can then search the package you need for your project.
I don't know if this is the most efficient way. From my research, I think the package are only applicable to my virtual environment; I still have to test that out to make sure.
I may have gone the long way around, but writing the proposed code did not work out. I am sure it works, but I am thinking I might not be using it in the right location.
Anyway, thanks for the help!

Related

Problem with installing any package in Pycharm Community Edition 2019.3.3 64 bit

I am fairly new to the programming world so I downloaded the latest version of python (3.8.1) and and Pycharm as my IDE.
Recently I wanted to add some packages (for example numpy) but found out im not able to. For some reason it wont recognize my pip (in the cmd) but for some weird reason Pycharm shows that there is a version of it (19.0.3).
That doesnt makes sence since in the cmd I cant find a version of it and even when I try to upgrade it from pycharm it still shows a warning that I might have the wrong version of it (I know the latest is 20.0.2). Thus I am unable to install any python package whatsoever (from cmd or pycharm).
I have tried reseting my python installation and my pycharm's configuration but I havent made any progress. Are there any posible solutions for an amateur like me?
Thanks in advance.
Brother that is great progress. I had issues like yours too, first learn how to set up a virtual environment for your project. You can install any package there for your project which will not interfere with other projects. Next set your pycharm's base interpreter to that environments bin/python. Hopefully it will resolve your issues.

Running Python code in Visual Studio - installing pip not working

Im trying to connect Linkedin to my Python.
and Im trying to run these in Visual Studio
For the below line,
$ pip install python-linkedin
it keeps throwing syntax error, not reading that $pip correctly.
I followed few videos and posts on Stackoverflow, and they suggested to click on "View" -> "Tools" -> Python environments, but I can`t find this "Tool" and Python environments from View option
Is there any alternative solutions to this?
Screenshot is my Visual Studio setting, if it helps..
VS setup
You need to install Python support for VS to work with python.
https://learn.microsoft.com/en-us/visualstudio/python/installing-python-support-in-visual-studio?view=vs-2019
Once you do that you should be able to see the python environment tab. It would look like this:
Another potential issue is that pip for python3.x is usually installed as pip3.x, not pip, so if you are using python 3x, you would need to change your settings.json accordingly.

problem installing and importing modules in python

I am installing python on windows10 and trying to install the opencv and numpy extentions in the command window. I get no error installing them and it says it is successfully installed. But when I try to check the installation and import cv2 it does not recognize it and give me the error: no module named cv2.
can anybody help me with this problem? Is there something wrong in installation process or do I need to install something else?
I checked the newest version of each and used the compatible one with my system.
Thanks.
One solution could be that you have 2 versions of python. So, go to the specific python's scripts directory and run: pip install numpy
If that too doesn't work, you can find the answers to this question on Why can't I import opencv3 even though the package is installed?, as stated by #Cut7er.
I have tried the solutions given to the above stated question myself also. But, they didn't work for me. So, another thing that you could try to use is this IDE called PyCharm. It ofcourse is much more beautiful that the IDLE, but it also has an inbuilt GUI controlled installation of binaries or packages. That would make things a lot easier. I have faced a lot of issues with packages for python and this IDE made things a lot easier. You can find it on https://www.jetbrains.com/pycharm/download/#section=windows.
You can also use anaconda. But, I found it a little difficult to use since, it has similar issues.
EDIT:
Seems like you are using PyCharm. But, you are installing libraries from your command prompt. So, see the answer to: ImportError: No module named 'bottle' - PyCharm. This answer guides you through how to install a certain library through your PyCharm window itself. So,
1) Go to Files>Settings
2) Search for "Interpreter" from the searching tab. Open the interpreter
3) You can now see a plus sign on the right. A click on it will open up a section on the left.
4) In the searching tab, search for numpy or opencv. Click on whichever module you want to install. And then click on the "install package" button on the bottom left. This will install the package for you.
5) Then click save. And run your file that says import cv/cv2.
This should probably do the trick.
Hope it helps!
Is it possible that you have 2 versions of python on your machine and your native pip is pointing to the other one? (e.g. you pip install opencv which installs opencv for python 2, but you are using python 3). If this is so, then use pip3 install opencv
I removed the Anaconda version on my machine, so I just have python 3.7 installed. I removed the python interpreter(Pycharm) and installed it again and the problem got fixed somehow!
I suspect you have two versions of python and the one you're using doesn't have opencv on it, because pip pointed to the wrong one.
A pragmatic solution assuming you're using the python version with conda is to just use conda to install cv2:
conda install -c menpo opencv
A more careful solution is to figure out how to get the pip that points to the python version you're using. On linux I can check that my pip points to my python like this:
:~$ which python
/home/kpierce/anaconda3/bin/python
:~$ which pip
/home/kpierce/anaconda3/bin/pip
So you see the pip and python versions are associated. On windows I suspect you do an analogous thing on the command line like
where python
where pip
And if they don't match, you might try
where python
where pip3
to see if those match. You need to use the pip that points to the correct python version. You can view the python version by entering the python interpreter and running
import sys
sys.version

Complete reinstall python, pycharm, qgis

My python installation is a mess.
Therefore I'd like to reinstall the entire installation of it. (Unfortunately,) I've also installed QGIS and PyCharm (mostly making it a mess) and I want to start clean..!
So, what is the best way to get rid of every little python thingy and what are the best packages/methods for reinstalling Python27, QGIS and PyCharm? Should I go for osgeo or not, should I first install Pycharm or Python etc. Hopefully you have some good thoughts and tools on this. I'm a fan of pip, so in the end I hope its possible just to use pip for installing the packages all around.
I'm working on Windows 7, 64bit (thanks for the headsup Karel)
Go to add/remove programs in windows and uninstall everything. Then reinstall everything. Do your Python install first and PyCharm should detect everything. I'd suggest doing the 32 bit Python install as some packages aren't compiled for 64 bit and it makes things a bit challenging to find and install them.
Pip is standard in the python install now. You'll see a check box in the installer for it, which is pre-checked. I'd change your install directory to something simple like C:\Python27
Other than that it should be pretty straightforward. However I doubt you really need to uninstall Python. You can just go to settings and under the interpreter section add the C:\Python27 directory. PyCharm is constantly scanning for installed modules, so it will know in real time that you've installed them. You can even install packaged via PIP while PyCharm is open and within second PyCharm will recognize it as a valid package.
If you're missing packages you can also import them in PyCharm and when you get the red underline saying it's missing, hover your mouse over it and hit alt+enter and you'll get a menu to install it.

Installing the Minisom package in Pycharm

I'm following this tutorial to get a better grasp on the concept of SOM.
This however requires me to install the Minisom package.
If i try the normal way of installing a package in Pycharm
File->Settings->Project settings->Project interpreter
Press on the "+" sign
I don't get any hits on the term "minisom"/"Minisom".
Any thoughts on how else I can install this package?
Are you sure to have selected the right interpreter? because if I try the same steps, works well.
On the GitHub page you can see that the python versions which were been tested are 2.7.3 and 3.2.3. Are you using one of these two?
Anyway, an alternative way to install MiniSom is:
Download or clone the project following this link
Enter in the directory
run python setup.py install (may require root privileges)
Let me know.

Categories

Resources