ImportError: cannot import name 'VideoCapture' - python

I'm writing a quick Python script that uses VideoCapture. At the start of the script, I have this:
from skvideo.io import VideoCapture
When I run the script, I get:
Traceback (most recent call last):
File "getVids.py", line 4, in <module>
from skvideo.io import VideoCapture
ImportError: cannot import name 'VideoCapture'
When I run:
pip3 install skvideo
I get:
Collecting skvideo
Could not find a version that satisfies the requirement skvideo (from versions: )
No matching distribution found for skvideo
Any idea how to fix / where to go from here?
Thanks!

The pip package providing this python module/package is call sk-video.
pip3 install sk-video

You should try
sudo pip install sk-video
as suggested in their installation guide. http://www.scikit-video.org/stable/

This smells like an environment variable problem. You shouldn't need sudo or administrator privileges to do this.
First, make sure that you run your script inside a virtual environment:
Create a Virtualenv: virtualenv my_env
Activate it: source my_env/bin/activate
Install your requirements: pip install sk-video
Run your script: python getVids.py

Related

No module named 'geopy'

I am trying to install geopy in a virtual environment created by miniconda. When I do pip install geopy, it gives me this:
(finalenv) MacBook-Pro ~ % pip install geopy
Requirement already satisfied: geopy in /usr/local/Caskroom/miniconda/base/envs/finalenv/lib/python3.6/site-packages (2.2.0)
Requirement already satisfied: geographiclib<2,>=1.49 in /usr/local/Caskroom/miniconda/base/envs/finalenv/lib/python3.6/site-packages (from geopy) (1.52)
The python version for this Finalenv is Python 3.6.13 :: Anaconda, Inc.
However, when I try to run my script:
import psycopg2
import geopy
I get an error that:
(finalenv) MacBook-Pro ~ % /usr/local/bin/python3 /Users/s/Desktop/s-project/v2.py
Traceback (most recent call last):
File "/Users/s/Desktop/s/file.py", line 15, in <module>
import geopy
ModuleNotFoundError: No module named 'geopy'
what am I missing here?
Since you are using Anaconda, you can try installing it through conda to see if the installation happens on the same folder. Open Anaconda CLI prompt as Administrator. You can try
conda config --add channels conda-forge
and
conda install -c conda-forge geopy.
/usr/local/bin/python3 is your OS python executable, not the one used by your virtualenv.
In order to run the script always with the python3 on the virtual environment (if it is activated), you can do this:
Add #!/usr/bin/env python3 at the beginning of the file. It will look like this:
#!/usr/bin/env python3
import psycopg2
import geopy
Give execution permissions to the file - in your case: chmod u+x v2.py
And run the file from the shell: ./v2.py

Why do I still get the "module not found" error even after having installed the package using pip install?

I am trying to create an image processing program using convolutions. I need the package scikit-image, specifically this:
from skimage.exposure import rescale_intensity
I have repeatedly installed scikit-image using pip install scikit-image in my terminal (Mac). I did this in the folder where my convolutions.py file is located (is this what is meant by the PYTHONPATH?). However, I always get an error message:
Traceback (most recent call last):
File "Convolutions.py", line 6, in <module>
from skimage.exposure import rescale_intensity
ImportError: No module named skimage.exposure
How do I solve the problem?
make sure you are installing the package on the same version of python which you are running. On a mac, python by default runs python-2.7, and the command python3 runs python-3.x. Also, pip by default installs packages to python-2.7. To install them on python3 try running
python3 -m pip install scikit-image
or simply
pip3 install scikit-image

Pytorch is installed but is not working on ubuntu 18.04

I am trying to install Pytorch via pip on ubuntu 18.04.I have python 3.6 and my laptop is HP-Pavilion notebook 15
The installation seems to be right because i get the message:
Installing collected packages: torch, torchvision Successfully
installed torch-1.3.1+cpu torchvision-0.4.2+cpu
i run the verification code and it is ok
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
However, when i close the terminal or reboot and try to run he same code i get the error:
Traceback (most recent call last):
File "torch.py", line 2, in
import torch
AttributeError: module 'torch' has no attribute 'rand'
How are you executing the python script? Which python are you using? Maybe you installed the package in a different python version?
Try to set alias to the python you want to use:
alias python=/usr/local/bin/python3.6
Then pip install the package with that python alias you will always be using.
python pip install <package name>
Python now will install the package in the python files with the alias python - heading to files: /usr/local/bin/python3.6
Let me know if the error still occurs!
Install pytorch using pip through the below command:
pip3 install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html
for any reference go through the official website of pytorch.
Change your file .py to another name, you named torch.py when you import torch it will call ur torch.py

sudo install - Python 3?

I'm new to Linux and I'm trying to install packages through a Makefile so users can run my Python 3 program.
sudo pip install python3-weather-api
However, even after uninstalling a previously installed version, the package seems to be going to the 2.7 version of Python.
Requirement already satisfied: python3-weather-api in /usr/local/lib/python2.7/dist-packages
Then, when I run the program, it can't find the module (it works locally in Python 3 just fine).
SystemExit: 1
Traceback (most recent call last):
File "project.py", line 11, in <module>
from weather import Weather
ImportError: No module named 'weather'
Is there a way I can point the original installation so when I run python3 project.py it can find the module?
Thanks very much!
I would recommend you to use pyenv to manage your Python installations, but, for now, try to run:
sudo pip3 install python3-weather-api

pip install package from url

pip install http://www.crummy.com/software/BeautifulSoup/unreleased/4.x/BeautifulSoup-4.0b.tar.gz
this installs package bs4, and everything is ok. But if I add this line to requirements.txt
http://www.crummy.com/software/BeautifulSoup/unreleased/4.x/BeautifulSoup-4.0b.tar.gz
and run
pip install -r requirements.txt
the output is
Downloading/unpacking http://www.crummy.com/software/BeautifulSoup/unreleased/4.x/BeautifulSoup-4.0b.tar.gz (from -r requirements.txt (line 40))
Downloading BeautifulSoup-4.0b.tar.gz (42Kb): 42Kb downloaded
Running setup.py egg_info for package from http://www.crummy.com/software/BeautifulSoup/unreleased/4.x/BeautifulSoup-4.0b.tar.gz
but the package doesn't get installed.
>>> import bs4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bs4
Note that this can happen if you have more than one interpreter installed and pip is using one (e.g., 2.6) and your python shell another (e.g., 2.7)
this happens when you are working with portable software or with more than one versions of Python / IDLE
what happens is that you can only install in the default path, otherwise you need to find a way to specifically install in the required path
(for me when I used pip from the windows cmd did not work in pycharm but when used pip from pycharm worked)

Categories