I am trying to learn the linearmodels package for python.
I want to do this by practicing with the data sets, as can be seen here.
Example code:
import numpy as np
from linearmodels.iv import IV2SLS
from linearmodels.datasets import mroz
data = mroz.load()
But my code breaks when i run data = mroz.load()
error message:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\...\\AppData\\Local\\Continuum\\anaconda3\\lib\\site-packages\\linearmodels\\datasets\\mroz\\mroz.csv.bz2'
I have pip version: 19.1.1
Conda can't find the package at all
and i have the latest version of linearmodels package: 4.13
The folder specified in the error message i can find, i.e. datasets\mroz but not the csv.bz2 file.
The same holds for every other data set i try to open.
Why am i not able to open the datasets?
let me know if you need additional information.
This is a bug in the package. If you download and unpack the source distribution you would find it lacks all *.csv.bz2.
I see two problems in the package. First, MANIFEST.in lists *.csv.bz. It must be *.csv.bz2 or *.csv.bz*.
Second, they tried to add the datasets in setup.py but also failed, not sure why. Perhaps the files must be declared as belonged to different subpackages, not to the main package.
Please report the bugs to the issue tracker.
Related
I'm trying to clone a repo to my machine to test changes for a pull request.
The repo in question is a clone of pytorch, and I want to add something to one of the files to fix an issue. I figured how to clone the repo, but I can't figure out how to import the pytorch libraries when I write a test file that contains something like:
import torch
x = torch.rand(5, 3)
print(x)
Where am I supposed to create a test.py file? How do I add pytorch (specifically my cloned version of pytorch) to the list of dependencies for Python to run with? I tried just creating a test.py file at the same level as the cloned repo, but i get the error message
"no module named torch.version". I am using VS code.
I'm new to using git and not extremely familiar with the structure of libraries like this. I tried looking through github, stack overflow and the pytorch docs but was unable to find an explanation.
Make sure your current selected interpreter doesn't contain pytorch, then before import torch, add the following code:
import sys
sys.path.append("\the folder that contains pytorch\")
Please have a try.
I am trying to convert lots of xyz file to raster, using gdal.Translate in Spyder. But I came across several problems.
I first try with convert only one xyz file. Code is like:
import os
from osgeo import gdal,osr
xyz = '1x1m_678494.xyz'
xyzraster = '1x1m_678494.tif'
translateoptions = gdal.TranslateOptions(projWin='EPSG:3879')
gdal.Translate(xyzraster,xyz,options=translateoptions)
the result is i can get a tif file, but without spatial reference. And there was no error or warning message. Then i thought it might relate to the gdal package. i found some similar issues here https://gis.stackexchange.com/questions/142215/gdal-translate-projection-errorhttps://github.com/conda/conda/issues/4050,I did set the GDAL_DATA to the path 'C:\Program Files\Anaconda3\Library\share\gdal'. This didn't solve my problem. checked my gdal version is 2.3.3 with python 3.7.3. I am trying to remove this gdal and install the newest version gdal 3.0.4 using conda. But there seems to be a incompatible issue.
In the same time, i found there is also independent install for GDAL, http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/. This tutorial has one step to set the GDAL_DATA and GDAL_DRIVER_PATH, but the paths are different from the GDAL_DATA installed by conda. I am very confused. Will the independent installed gdal works different from the conda installed gdal? Or i just need one of them?
Then i leave the spatial reference issue behind, and tried convert multiple xyz to a geotiff. But got some other issues. code is like:
import os
import gdal
import glob
path = 'D:\\Data\\1m\\'
gdal.BuildVRT(path+'out.vrt',glob.glob(path+'\\*.xyz'))
gdal.Translate(path+'out.tif',path+'out.vrt')
The error is ValueError: Received a NULL pointer.
Can anyone help me out, please?
** gdal.TranslateOptions(projWin=(zip(ulx,uly,lrx,lry)),projWinSRS='EPSG:3879')
Is where the first part went wrong.
Working with R in Python using rpy2 on windows 7.
I need to open some rasters as RasterLayer using the function raster() from the raster package. I manage to install the package, but not to use its function.
I install the packages that I need (rgdal, sp, raster, lidR, io) using
utils.install_packages(StrVector(names_to_install))
names_to_install is a list of the packages that are still not installed. This works fine.
I know how to try the "basic" functions, like sum, and it works:
import rpy2.robjects as robjects
function_sum = robjects.r['sum']
But the same doesn't seem to work with the raster function from the raster package:
function_raster = robjects.r['raster']
since I get the error:
LookupError: 'raster' not found
I also tried the following:
raster_package = importr('raster')
with the intention to be able to run the next and load my raster file:
raster_package.raster(my_raster_file)
but the first line (import('raster')) causes the crash of python and I get the error:
Process finished with exit code -1073741819 (0xC0000005)
This doesn't happen with other loaded packages like rgdal, but with the raster package and with the lidR package I get the error.
I looked up this error, seems to be access violation, but I don't know what I can do about it and why it only happens with certain packages.
I expect to be able to call the raster function from the package raster.
Edit
I tried it on a computer with windows 10 and the error doesn't show anymore when running
raster_package = importr('raster')
Still would be nice to know what is the problem with Windows 7 and if there is any solution.
rpy2 does not currently have Windows support. This is not a final situation, most of what is likely needed is contributions to finalize this: https://github.com/rpy2/rpy2/blob/master/rpy2/rinterface_lib/embedded_mswin.py
I have installed spacepy using the following command (MacOS Mojave):
pip install git+https://github.com/spacepy/spacepy.git
But I keep getting this error while trying to from spacepy import pycdf:
Exception: Cannot load CDF C library; checked . Try 'os.environ["CDF_LIB"] = library_directory' before import.
I have tried following the directions from their website, but it seems like those directions are a bit outdated.
You can do something like:
import os
os.environ["CDF_LIB"] = "~/CDF/lib" # Give the path of the cdf library
# e.g. in this case the library is in your home directory.
Before doing:
from spacepy import pycdf
Source of the error can be found on this SpacePy website.
The cdf library is available here.
Basically, you need to set up the CDF_LIB (if pycdf has a trouble finding it) before importing the module. You can read the documentation here.
Context
Steps taken:
Environment Setup
I've installed protobufs via Home Brew
I've also followed the steps in the proto-bufs python folder's readme on installing python protobufs - namely running the python setup.py install command
I've using the protobuf-2.4.1 files
Coding
I have a python file (generated from a .proto file I compiled) that contains the statement, among other import statements, but I believe this one is the one causing issues:
from google.protobuf import descriptor_pb2
The above python file, I'm importing in another python file, it's
this python file that I want to write up logic for parsing the
protobufs data files I receive
Error received
I get this error when running that file:
Steps taken to fix
Searched google for that error - didn't find much
Looked at this question/answer Why do I see "cannot import name descriptor_pb2" error when using Google Protocol Buffers?
I don't really understand the above questions selected answer,I tried to run the command in the above answer protoc descriptor.proto --python_out=gen/ by coping and pasting it in the terminal in different places but couldn't get it to work
Question
How do I fix this error?
What is the underlying cause?
How do I check if the rest of my protobuf python compiler/classes are set up correctly?
I've discovered the issue. I had not run the python install instructions the first time I tried to compile this file. I recompiled the file and this issue was fixed.