Pytorch won't install in PyCharm on MacOS - python

I'm new to the MacOS and I have recently downloaded PyCharm on it. I was able to successfully install some packages like numpy, matplotlib, sympy, etc. However, Pytorch won't get installed; not through PyCharm nor through the Terminal. These are the commands I tried in the Terminal (other than attempting to install them directly from PyCharm):
pip install torch
pip install torch torchvision torchaudio
I could post the error messages but some are quite lengthy :(
I'm using Python 3.9 interpreter with pip on the latest version (20.2.4) (everything else is also up to date). Running this on the new Mac Mini (running the M1 chip).
Any ideas on what I should do? Thanks!!!

Try building from the source code, run these commands
git clone https://github.com/pytorch/pytorch.git
cd pytorch
git submodule update --init --recursive
python3 setup.py build
python3 setup.py install

Are you using a venv? If so you could try checking the box "install to user's site packages directory" in the Project Interpreter settings when you add a package.

Related

setup.py install for dlib: finished with status 'error'

I'm having problems installing Adam Geitgey's face_recognition library on my Windows PC.
I followed this tutorial for installing dlib with Python bindings on windows and I've successfully installed the requirements listed there.
However, trying to install dlib with pip throws the error
setup.py install for dlib: finished with status 'error'
How can I go about resolving this?
In order for dlib (with its Python bindings) to work well for you on Windows, you need to use a Python installation whose version is 3.6 or lower.
I understand you're using the latest version of Python. If I'm correct in my assumption that you're working with Python 3.8, then you'll have to follow these steps:
Install Python 3.6 on your PC — take note of the installation path as you'll need this for creating the appropriate virtual environment.
Create a Python 3.6 virtual environment — this will serve to isolate the dependencies of your current project.
Assuming your Python 3.6 was installed to C:\Users\Mfonism\AppData\Local\Programs\Python\Python36 (like it was on my PC :)), you'll create your virtual environment thusly (from your project directory):
c:\> C:\Users\Mfonism\AppData\Local\Programs\Python\Python36\python.exe -m venv env36
venv is the Python virtual environment module.
env36 is the name of the virtual environment you're creating.
Activate the so-created virtual environment.
c:\> env36\Scripts\activate
The name of the virtual environment (env36) should now appear in the terminal.
UPDATE: IGNORE THIS BLOCK
Install your project dependencies with pip.
pip install face_recognition
If this fails, use the --no-cache-dir option to circumvent cached versions of the dependencies.
pip install face_recognition --no-cache-dir
UPDATE: DO THIS INSTEAD
You will need to install specific versions of dlib and face_recognition. And you will need to install dlib first, or face_recognition will try to install the latest version of it, and this will fail.
So:
Install dlib 19.8.1
pip install dlib==19.8.1
Then install face_recognition 1.2.2
pip install face_recognition==1.2.2

Trouble installing some libraries in python (oauth2client and gspread)

I'm using python 3.7 (environment created by anaconda) and trying to run python code that uses some google libraries but I don't really know how to install them.
From PyCharm IDE (Settings -> Project Interpreter -> Available Packages) I cannot find those packages to install.
And from terminal, running 'pip install --upgrade oauth2client' or 'pip3 install --upgrade oauth2client' doesn't seem to work either.
What I don't understand is: to install packages/libraries on python 3.x, should i only use pip3? But what if there is more than one python environment? On which one pip will install those libraries?
If you're using Anaconda, you should also have an Anaconda Prompt (py37) program that functions like the terminal. Typing pip install --upgrade oauth2client into Anaconda Prompt (py37) will install the upgrade into your current python environment. Alternatively, you can use conda install with more options (including specifying which environment you want).

How to import packages into Pycharm using PIP?

I'm trying to install a package onto Pycharm using PIP. I am running Anacondas on a Pycharm IDE. I know that you use the project interpreter to install packages and I also know that the package should be located under PyPi but when I go to the project interpreter and click add package the package I'm trying to install doesn't appear under the list of available packages.
I know that you can install the package using PIP and I have PIP installed through Anaconda although I am unsure how to run a pip command through Pycharm. I've tried typing it into the cmd console and the python code and neither seems to have any effect...
The package I'm trying to install is: https://github.com/seatgeek/fuzzywuzzy.
The pip command to install it is: pip install fuzzywuzzy but I am unsure as to where I'm supposed to run that command.
I'm fairly new at Python so any help would be much appreciated!
Thank you!
I found someone else's answer that works for me:
You need to use
import pip
pip.main(['install','packagename'])
Which allows you to manually install packages through pip using Python code.
This is guide for installing the pip packages from Python Console in Pycharm IDE.
Do not forget to run Pycharm as administrator if you are using windows OS before installing the packages.
First of all import the pacakage of pip in python console.
import pip
Installation of Package.
pip.main(['install', '<package_name>'])
Examples
The below command will upgrade the version of package setuptools.
pip.main(['install','--upgrade','setuptools'])
The below command will install the scikit-learn and numpy packages.
pip.main(['install','numpy','scikit-learn'])
The below command will uninstall the scikit-learn package.
pip.main(['uninstall','scikit-learn'])
I was with the same problem, all i did was : Configure the project interpreter to the Python3 inside the venv you are using the pip install.
Remember to activate the venv.
That's it , now you can use the pip install on pycharm or on prompot.
The problem is that even with the "venv/lib/sitepackeges" in the your project's sys.path the pycharm looks only for the packages where the project interpreter is.

Trouble installing OpenAI's gym

I would like to install the entire Open AI gym package.
After (I am on a mac) brew install cmake , sudo pip install gym[all] gives me the following error
I am using anaconda 4.3.22. I am not in a conda virtual environment. which python outputs /anaconda/bin/python. The interpreter that anaconda uses is python 3.6.1. Just running sudo pip gym (which must be the minimal version) ran fine.
Thanks for the help.
I have successfully installed gym on my mac laptop, and brew install swig will solve the problem.

Pycharm/Python OpenCV and CV2 install error

I've been trying to install both OpenCV and cv2 from both Pycharm and from the terminal as suggested using:
pip install --user opencv
pip install --user cv2
but I'm getting the following error for them:
Collecting opencv
Could not find a version that satisfies the requirement opencv (from versions: )
No matching distribution found for opencv
and
Collecting cv2
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
How can I fix these and install the packages properly? I'm using python 3.4.
You are getting those errors because opencv and cv2 are not the python package names.
These are both included as part of the opencv-python package available to install from pip.
If you are using python 2 you can install with pip:
pip install opencv-python
Or use the equivilent for python 3:
pip3 install opencv-python
After running the appropriate pip command your package should be available to use from python.
This the correct command that you need to install opencv
pip install opencv-python
if you get any error when you are trying to install the "opencv-python" package in pycharm, make sure that you have added your python path to 'System Variables' section of Environment variables in Windows.
And also check whether you have configured a valid interpreter for your project
I ran into the same problem. One issue might be OpenCV is created for Python 2.7, not 3 (not all python 2.7 libraries will work in python 3 or greater). I also don't believe you can download OpenCV directly through PyCharm's package installer. I have found luck following the instructions: OpenCV Python. Specifically:
Downloading and installing OpenCV from SourceForge
Copying the cv2.pyd file from the download (opencv\build\python\2.7\x64) into Python's site-packages folder (something like: C:\Python27\Lib\site-packages)
In PyCharm, open the python Console (Tools>Python Console) and type:import cv2, and assuming no errors print cv2.__version__
Alternatively, I have had luck using this package opencv-python, which you can straightforwardly install using pip with pip install opencv-python
Good luck!
python3.6 -m pip install opencv-python
will install cv2 in python3.6 branch
On Windows:
!pip install opencv-python
Try this. I am using Jupyter notebook (OS: Ubuntu 16.04 LTS on Google Cloud Platform + on Windows). Executed following command in the Jupyter notebook to install opencv:
!pip install opencv-contrib-python #working on both Windows and Ubuntu
After successful installation you will get following message:
Successfully installed opencv-contrib-python-4.1.0.25
Now restart the kernel and try to import opencv as:
import cv2
The same command can be used to installed opencv on Windows as well.
SOLUTION 2: try following commands to install opencv:
For Ubuntu:
Run following command from terminal:
sudo apt-get install libsm6 libxrender1 libfontconfig1
Restart Jupyter notebook kernel and execute following command:
!pip install opencv-contrib-python
NOTE: You can run all the above commands from the terminal as well without using '!'.
Keep it simple and just run.
pip install opencv-python
This is the simplest way of installing opencv.
If you still face issue, create a virtual environment and try installing opencv.
I rather use Virtualenv to install such packages rather than the entire system, saves time and effort rather than building from source.
I use virtualenvwrapper
Windows user can download
pip install virtualenvwrapper-win
https://pypi.org/project/virtualenvwrapper-win/
Linux follow
pip install opencv-python
opencv-python
If processing a video is required
pip install opencv-contrib-python
opencv-contrib-python
If you do not need GUI in Opencv
pip install opencv-contrib-python-headless
opencv-contrib-python-headless
here is a tutorial that worked for me without any problem.
Copied from the site above the important part:
Download the OpenCV version corresponding to your Python installation
from here. In my case, I’ve used
opencv_python-3.1.0-cp35-cp35m-win32.whl.
Now, open a cmd window like before. You can open this directly in your
Downloads folder if you SHIFT and right click inside it. The idea is
to open a cmd window where you’ve downloaded the above [...] file. Use
the [...] command to install [...] OpenCV:
1 pip install "opencv_python-3.1.0-cp35-cp35m-win32.whl"
Additional note: don't forget to change the name of the downloaded file in the command you use.
Apparently by installing opencv, you'll have access to cv2 too.
Installing opencv is not that direct.
You need to pre-install some packages first.
I would not recommend the unofficial package opencv-python. Does not work properly in macos and ubuntu (see this post). No idea about windows.
There are many webs explaining how to install opencv and all required packages.
For example this one.
The problem of trying to install opencv several times is that you need to uninstall completely before attempting again, or you might end having many errors.
you must install opencv-python
pip/pip3 install opencv-python
if you try import opencv-python, receive error.
Fix this error, use the import cv2
How about try some different mirrors?
If you are in China, I highly recommend you try:
sudo pip install --index https://pypi.mirrors.ustc.edu.cn/simple/ opencv-contrib-python
If not, just replace the url address to some other mirrors you like!
Good luck.
this will help you
pip3 install opencv-python
this is the snippet of successful installation
First step:
pip uninstall numpy
pip uninstall opencv-python
Second step:
pip install numpy
pip install opencv-python
I had the same problem. Here are the steps for Windows 10 users.
Open CMD: win+r then type cmd. Now,
Type pip install virtualenv
Create a Virtual Environment, Type virtualenv testopencv
Get Inside testopencv, Type cd testopencv
Activate the Virtual Environment, Type .\Scripts\activate
Now Install Opencv, Type pip install opencv-contrib-python --upgrade
Let's test Opencv, Type Python then import cv2 hit enter then type print(cv2.__version__) to check if its installed
Now, open a new cmd, win + r then type cmd, repeat step 6. If it gives you an error.
Go inside the testopencv folder, inside lib. Copy everything, go to your python directory, inside lib folder paste it and skip that are already present.
Again open a new cmd, repeat Step 6.
Hope it helps.
In win, download the py based latest numpy and Opencv from Unofficial Windows Binaries for Python Extension Packages and pip install its source in cmd. Later copy site-package folder from main py lib to venv lib.
In jetso nano this work for me.
$ git clone https://github.com/JetsonHacksNano/buildOpenCV
$ cd buildOpenCV
When I was facing this issue I used to install OpenCV in pycharm installed package panel where we can find under the settings tab. Search "OpenCV-python" and install it in the installed package panel of right interpreter.
First run from cmd
pip --version
to make sure that you have the updated version installed.
Then run
pip install opencv-python
Go through with this link: https://learnopencv.com/install-opencv-4-on-raspberry-pi/
you can install OpenCV perfectly with out any error. but the problem was it will take lot of time to install.
I had used pi3 model B+ with 32GB class10 SD card for me it took more than 12 hours for complete installation.
If you still find any error to install open-cv in your mac, try this:
opencv-python==4.2.0.34
This worked for me.

Categories