I'm writing a data extraction from xls python script using xlrd. I'm having trouble however with pip, I just managed to get a positive reply from the cmd when i requested (I had some trouble with it at first, but a few posts helped out)
py -m install requests
The response I now get is: "Requirement already satisfied." (with some mention of update since my pip version is 6.0.8 and there's a 7.0.1 available)
However, when I run my code part of which can be seen below I get a syntax error.
import xlrd
from xlrd import open_workbook
import xlwt
workbook = xlrd.open_workbook('editable.xls')
The error:
File "C:\Python34\lib\site-packages\xlrd__init__.py", line 1187
print "EXTERNSHEET(b7-):"
^ SyntaxError: invalid syntax
I run your program on Ubuntu/Linux and it runs fine.
I will recommend to follow my instructions for installing the xlrd on your Windows machine.
From here download the latest version of the xlrd.
Then extract the file, and using the command prompt in the new xlrd directory type:
python3 setup.py install
Unfortunately I don't own a Windows machine so I can't guaranteed to you that this is the right way to install it.
The trick was that you should run the setup.py using the python3 and not the python
(note that on my machine, I run the above command using sudo, which means in Linux administration permissions, so if you have any problems try to run your command prompt with administration permissions.)
I test this code on my Ubuntu machine:
import xlrd
from xlrd import open_workbook
workbook = xlrd.open_workbook('Untitled.xls')
I remove the import xlwt as I don't have this module, please try and let me know.
Edit: Also you will need the setuptools installed on your computer.
Related
I was able to install xgboost on my mac and have it so that I can import the module without any errors. However I cannot use it. When I try to import XGBRegressor. I get the following error :
cannot import name 'XGBRegressor' from 'xgboost' (unknown location).
Some of the support for this type of problem says that there may be more than one xgboost location, and that python is selecting the incorrect xgboost, however I have not been able to find how to fix this problem.
When I print the xgboost.__file__ location, it returns 'None'. However I know its in the site-packages folder in my python path.
I have python 3.9
Maybe this.
conda install -c conda-forge xgboost=0.6a2
Then, restart Spyder and re-run!
Before I explain my problem I want to start by saying that I have looked all over this site for an answer and tried almost all of them, to no avail.
I am on a windows machine, in a virtual environment. I have a command prompt opened in the virtual environment. I have already pip installed over a dozen modules that are being imported into my script and working perfectly. When I run the line:
from bs4 import BeautifulSoup
I get this error:
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
In my command prompt I can do 'pip list' and see beautifulsoup4 version 4.9.0. As well as in my virtual environment folder I can go into Lib\site-packages and I see all of my other installed packages that work in my script, along with a folder called 'bs4' and one called 'beautifulsoup4-4.9.0.dist-info'. I have also tried pip uninstall beautifulsoup4 and then re installed it, confirming that it did not show up in pip list between running those.
I am completely at a loss for why I cannot access the bs4 module. Anyone have any ideas for me to try? Thanks in advance.
EDIT: I am currently using VS Code and have pip installed several other modules including pymysql and google-api packages. I have successfully connected to my gmail and Amazon RDS database, so i know the other modules are working properly. For some reason its only BeautifulSoup4 I am having issues with.
EDIT 2: I opened up ipython from my virtual environment, and I entered from bs4 import beautifulsoup and i get this error.
ImportError: cannot import name 'beautifulsoup' from 'bs4' (C:\Users\Brian\Desktop\Projects\VirtualENVs\test_venv\Lib\site-packages\bs4\__init__.py)
EDIT 3: I finally just opened a new command prompt and pip installed beautifulsoup4 onto my computer outside of the virtual environment and now it works fine.
Tried to run a script I wrote yesterday again today and ran into this:
ImportError: cannot import name 'Repo' from 'git' (/usr/local/lib/python3.7/site-packages/git/__init__.py)
I am at a complete loss. On a new computer so the only thing different install wise would have been that I installed pycharm. I am currently trying to run through bash shell on a mac. The exact code was running as excepted earlier, no code changes.
Things I have tried:
uninstalling/reinstalling python
uninstalling/reinstalling pip
uninstalling/reinstalling gitpython
Running on:
mac catalina
python version 3.7.6
pip version 20.0.1
As a side note, the script works as intended until the automated git push. Wondering if I should just make the os calls myself and not worry about this?
I really dont understand what I did/am doing wrong here.
EDIT:
Again, sorry as this is my first mac computer. I did a brew uninstall of python3 and reinstalled through the app store to 3.8.
ImportError: cannot import name 'is_cygwin_git' from partially initialized module 'git.util' (most likely due to a circular import) (/Library/Frameworks/Python.framework/
I know cygwin is for windows, but I figured I'd play along and trying a pip install pycygwin.
Install threw an error asking for cython, so I did another pip install and tried again. The pycygwin then complained gcc was missing so I did a brew install of gcc. With gcc installed and correctly on path, it still says it cant find it and exits with
build/cygwin/_cygwin.c:611:10: fatal error: 'sys/cygwin.h' file not found
#include <sys/cygwin.h>
^~~~~~~~~~~~~~
1 error generated.
error: command 'gcc' failed with exit status 1
Thinking I might just try a different package manager? Currently, an attempt to rerun the script yeilds
ImportError: cannot import name 'Repo' from partially initialized module 'git' (most likely due to a circular import)
To which I investigated but I shouldn't have any overlapping dependancies.
On the script throwing the error I'm using:
import csv
import yaml
import os
from git import Repo
and on the wrapper I made and imported, I'm using:
import subprocess
import re
Will update if I get any further on this, would love some suggestions.
EDIT:
Importing using just import git works throws a different error, like the python is trying to get itself?
ImportError: cannot import name '<file name>' from '<file name>'
If I change the file name and try to run it, it comes backs with:
ImportError: cannot import name '<old file name>' from '<old file name>'
***FIXED****
Uninstall of python through homebrew
Reinstall of python through mac app store
Uninstall/Reinstall of modules through pip
Saving the file under a new name and deleting the old one
Still have absolutely no idea why/how this happened but the above worked for me. If anyone knows why something like this can happen, I would love to know. Cheers.
I just tried to use pd.HDFStore in IPython Notebook with a Python 3 kernel (Anaconda 2&3 on Ubuntu 14.04)
import pandas as pd
store = pd.HDFStore('/home/Jian/Downloads/test.h5')
but it throws the following error
ImportError: HDFStore requires PyTables, "libhdf5.so.9: cannot open shared object file: No such file or directory" problem importing
I initially thought it's because pytables is somehow missing, but when I check $source activate py34 and $conda list, pytables 3.2.0 is already installed under anaconda python3 environment.
Also, if I switch to Python 2, for example, $source activate py27 and start ipython notebook, it works properly and no import error is thrown.
I guess that I must miss something for configuring pytables under anaconda python 3 env, but I cannot figure it out. Any help is highly appreciated.
Update:
I just tried on a fresh install of Anaconda3-2.3.0-Linux-x86_64 from official website and it ends up with the same error. When I try $locate libhdf5.so.9 in command line, nothing shows up.
This is a known issue that we are working on. When it is fixed, conda update --all will update the libraries and fix the issue.
I'm trying to run my code and I don't know what specific package I need in order to get my import statement to work. Below is my header and I keep getting an error saying ImportError no module named statistics. I have looked at a bunch of different pages to see where I can download a solution, but I am trapped. I know my code works because I ran it on my schools lab. If anyone can help, that' be great!
Just note I am a beginner and am using Linux on my virtual machine with Python 2.7
import sys
import requests
import matplotlib.pyplot as plt
import statistics as stat
Statistics "A Python 2.* port of 3.4 Statistics Module" (PyPI).
If you use 2.7.9, you will have pip installed, and pip install statistics within the 2.7 directory should install the module for 2.7 (I am not a pip or virtual machine expert, so might be slightly off.)
It comes pre-installed in python --Version 3. To import in python version 2 in Ubuntu, open Terminal and type
sudo pip install statistics
Enter your password and it will get installed.
Ps: you need to have pip already installed.
You need to be using python 3.4 to import statistics. Upgrade to the current version and you should have no problems.