Error when trying to install library permanently on google colab - python-3.x

I'm trying to install library permanently on google colab. So I run this code first:
import os, sys
from google.colab import drive
drive.mount('/content/drive', force_remount = True)
my_path = '/content/notebooks'
os.symlink('/content/drive/My Drive/Colab Notebooks/my_env', my_path)
sys.path.insert(0, my_path)
there's no error running above code.
However, when I run the code below, I got the error:
!pip install --target=$my_path jdc
Collecting jdc
Downloading https://files.pythonhosted.org/packages/5a/cb/9afea749985eef20f3160e8826a531c7502e40c35a038dfe49b67726e9a0/jdc-0.0.9-py2.py3-none-any.whl
Installing collected packages: jdc
Successfully installed jdc-0.0.9
ERROR: Exception:
Traceback (most recent call last):
File "/usr/lib/python3.6/shutil.py", line 550, in move
os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-target-21y8mx4d/lib/python/jdc' -> '/content/notebooks/jdc'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/cli/base_command.py", line 153, in _main
status = self.run(options, args)
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/install.py", line 505, in run
options.target_dir, target_temp_dir, options.upgrade
File "/usr/local/lib/python3.6/dist-packages/pip/_internal/commands/install.py", line 563, in _handle_target_dir
target_item_dir
File "/usr/lib/python3.6/shutil.py", line 561, in move
symlinks=True)
File "/usr/lib/python3.6/shutil.py", line 321, in copytree
os.makedirs(dst)
File "/usr/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/content/notebooks/jdc'
Is there a way to solve this?

First target your directory where you want to install the library like this:
%cd "/path/to/your/directory"
Then install using ```pip``:
pip install jdc

Related

Poppler is installed: why do I get an error using pdf2image on python3?

I am using python 3.7.4 on a macOS 10.14.6 and I am trying to use pdf2image to convert a pdf file into an image. So I have installed poppler with Homebrew. I get an error message when I try to convert the PDF.
Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 240, in _page_count
proc = Popen(command, env=env, stdout=PIPE, stderr=PIPE) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session) File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'pdfinfo': 'pdfinfo'
I use the following code:
from pdf2image import convert_from_path, convert_from_bytes
from pdf2image.exceptions import (
PDFInfoNotInstalledError,
PDFPageCountError,
PDFSyntaxError
)
images = convert_from_path('test.pdf')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/michelebutturini/Desktop/Segmentation.py", line 16, in <module>
images = convert_from_path('test.pdf')
File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 54, in convert_from_path
page_count = _page_count(pdf_path, userpw, poppler_path=poppler_path)
File "/usr/local/lib/python3.7/site-packages/pdf2image/pdf2image.py", line 244, in _page_count
raise PDFInfoNotInstalledError('Unable to get page count. Is poppler installed and in PATH?')
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
I've had this problem on Google Colab and I've fixed with this command:
!apt-get install poppler-utils
I had a similar issue, and found my answer here:
https://github.com/Belval/pdf2image/issues/101
What SamikhaAgarwal said was:
"These pdf2image and pdftotext library backend requirement is Poppler, so you have to install
conda install -c conda-forge poppler
Then the error will be resolved, and if still it doesn't work for you, then you can follow http://blog.alivate.com.au/poppler-windows/ to install this library.
Maybe try:
brew install poppler
This worked for me.

Unable to install python 3.7 packages Fiona, lxml, pandas, Pillow in mac 10.14.3

I was trying to install python 3.7 virtualenv packages in my new mac system with runs mac os 10.14.3. But system installation failed due to environment error
Packages:
lxml==3.8.0
Pillow==4.1.1
Fiona==1.7.10.post1
pandas==0.20.2
I Have attached the full crash report in https://pastebin.com/tzMwwHjB
Failed building wheel for Fiona
Failed building wheel for lxml
Failed building wheel for pandas
Failed building wheel for Pillow
Error checking for conflicts.
Traceback (most recent call last):
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2897, in _dep_map
return self.__dep_map
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2691, in __getattr__
raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2888, in _parsed_pkg_info
return self._pkg_info
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2691, in __getattr__
raise AttributeError(attr)
AttributeError: _pkg_info
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 503, in _warn_about_conflicts
package_set, _dep_info = check_install_conflicts(to_install)
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_internal/operations/check.py", line 108, in check_install_conflicts
package_set, _ = create_package_set_from_installed()
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_internal/operations/check.py", line 47, in create_package_set_from_installed
package_set[name] = PackageDetails(dist.version, dist.requires())
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2635, in requires
dm = self._dep_map
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2899, in _dep_map
self.__dep_map = self._compute_dependencies()
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2908, in _compute_dependencies
for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2890, in _parsed_pkg_info
metadata = self.get_metadata(self.PKG_INFO)
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1410, in get_metadata
value = self._get(self._fn(self.egg_info, name))
File "/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1522, in _get
with open(path, 'rb') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/Fiona-1.8.4.dist-info/METADATA'
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/Users/titus/.virtualenvs/julo-ana/lib/python3.7/site-packages/Fiona-1.8.4.dist-info/RECORD'
Can any one know solution for this. Im trying to fix this for last two days still facing it.
Use the supported version of Python
Try the following:
pip3 install --user package-name (for Python3)
pip install --user package-name (for Python2)
Note: Replace package-name with pandas, lxml, etc

Selenium using Python in 2019 on mac

I'm a non-programmer trying to use Automate the Boring Stuff with Python to do exactly that. I watched all the videos and thought I was ready, but as I tried to get going I'm stuck on square zero.
I'm on a Mac OSx Mojave Version 10.14.2
Successfully installed Python 3.7.2
I'm trying to follow this chapter: http://automatetheboringstuff.com/chapter11/
Successfully installed Selenium because:
import selenium
does not give an error.
but when I run this:
from selenium import webdriver
browser = webdriver.Firefox()
I get this error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'your\\path\\geckodriver.exe': 'your\\path\\geckodriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'your\path\geckodriver.exe' executable needs to be in PATH.
>>> driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'your\\path\\geckodriver.exe': 'your\\path\\geckodriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
driver = webdriver.Firefox(executable_path=r'your\path\geckodriver.exe')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'your\path\geckodriver.exe' executable needs to be in PATH.
I've tried everything in this: Selenium using Python - Geckodriver executable needs to be in PATH and I don't think it works anymore.
I've installed geckodriver and tried appending it to PATH but nothing seems to work. geckodriver is installed in /usr/local/bin/ and I've appended it to path by running export PATH=$PATH:/path/to/geckodriver and export PATH=$PATH:/usr/local/bin/geckodriver but I keep getting the same error
I've tried having both the newest Firefox and Firefox v46 installed because I read somewhere that it doesn't work after that version.
Any help is much appreciated.
I suggest to install with pip
pip install geckodriver-autoinstaller
and then add this code
import geckodriver_autoinstaller
# Check if the current version of geckodriver exists
# and if it doesn't exist, download it automatically,
# then add geckodriver to path
geckodriver_autoinstaller.install()
Set your executable_path
from selenium import webdriver
webdriver.Firefox(executable_path=r'path\to\geckdriver\geckodriver.exe')
executable_path –
Full path to override which geckodriver binary to use for Firefox 47.0.1 and greater, which defaults to picking up the binary from the system path.
from documentation
Edit: also works on lower versions firefox
Edit 2:
Perhaps you could verify the executable can be found by python itself.
import os.path
os.path.exists(file_path)

I can't install any package with pip anymore,

I've always used pip in installing python packages but for some unexplained reason it just stopped working. I have tried the following but still not working
i upgraded pip
i rolled back pip
-i uninstalled my python distribution and reinstalled/upgraded it. Here is a trace back of the kind of error i get whenever i try
installing a package with pip
OS- windows 10
pip install profanity
Collecting profanity
Using cached https://files.pythonhosted.org/packages/f6/b4/07d53456462e26eee50abcae787c9380c01731ccc0b6c96233770e546989/profanity-1.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "C:\Users\MEME\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources\__init__.py", line 2698, in get_entry_map
ep_map = self._ep_map
File "C:\Users\MEME\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources\__init__.py", line 2669, in __getattr__
raise AttributeError(attr)
AttributeError: _ep_map
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\MEME\AppData\Local\Temp\pip-install-xg7obvs0\profanity\setup.py", line 72, in <module>
['profanity=profanity:main'],
File "C:\Users\MEME\AppData\Local\Programs\Python\Python37\lib\site-packages\setuptools\__init__.py", line 128, in setup
_install_setup_requires(attrs)
File "C:\Users\MEME\AppData\Local\Programs\Python\Python37\lib\site-packages\setuptools\__init__.py", line 117, in _install_setup_requires
(k, v) for k, v in attrs.items()
File "C:\Users\MEME\AppData\Local\Programs\Python\Python37\lib\site-packages\setuptools\dist.py", line 370, in __init__
for ep in pkg_resources.iter_entry_points('distutils.setup_keywords'):
File "C:\Users\MEME\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources\__init__.py", line 645, in iter_entry_points
entries = dist.get_entry_map(group)
File "C:\Users\MEME\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources\__init__.py", line 2701, in get_entry_map
self._get_metadata('entry_points.txt'), self
File "C:\Users\MEME\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources\__init__.py", line 2412, in parse_map
raise ValueError("Entry points must be listed in groups")
ValueError: Entry points must be listed in groups
Command "python setup.py egg_info" failed with error code 1 in
C:\Users\MEME\AppData\Local\Temp\pip-install-xg7obvs0\profanity\

Issues installing pyzmail or imapclient on python 3.5, pip throws a value and syntax error

I am trying to download a couple of packages in python 3.5 but pip keeps throwing an exception(via pip install pyzmail), please see below:
How do I overcome this issue?
Exception:
Traceback (most recent call last):
File "c:\users\chiruld\appdata\local\programs\python\python35\lib\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "c:\users\chiruld\appdata\local\programs\python\python35\lib\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "c:\users\chiruld\appdata\local\programs\python\python35\lib\pip\req.py", line 1229, in prepare_files
req_to_install.run_egg_info()
File "c:\users\chiruld\appdata\local\programs\python\python35\lib\pip\req.py", line 292, in run_egg_info
logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.setup_py, self.name))
File "c:\users\chiruld\appdata\local\programs\python\python35\lib\pip\req.py", line 265, in setup_py
import setuptools
File "c:\users\chiruld\appdata\local\programs\python\python35\lib\setuptools__init__.py", line 2, in
from setuptools.extension import Extension, Library
File "c:\users\chiruld\appdata\local\programs\python\python35\lib\setuptools\extension.py", line 5, in
from setuptools.dist import _get_unpatched
File "c:\users\chiruld\appdata\local\programs\python\python35\lib\setuptools\dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
If you are using Windows.., try right clicking 'cmd.exe' and select 'Run as Administrator' and click 'Yes' to allow the following program to make changes to this computer.

Resources