When I tried to import dicom in pydicom package I got error.
I performed the following steps.
Downloaded the pydicom-0.9.9.tar file,extracted and performed 'jython setup.py install' in cmd.But its not working.
Is this due to compatability of jython with python?
How to make pydicom is working in jython?
There is a bug in Jython on the bytecode files size. That is, Jython can’t compile the file if a module have huge bytecode size and unfortunately PyDicom have 2 such files. So, The work around is to split the files into junks and try installing.
This is a temporary work around and this issue has been resolved in Jython2.7.1 version. For now, try the following
Split the “pydicom-0.9.8\dicom_dicom_dict.py” file into multiple files(4) files with 700 entries in a list.
Split the “pydicom-0.9.8\dicom_private_dict.py” files into multiple files with 700 entries in each
Search and change the usage of _dicom_dict.py contents in the pydicom package
example: go to datadict.py and edit the following
from dicom._dicom_dict_1 import DicomDictionaryOne
from dicom._dicom_dict_2 import DicomDictionaryTwo
from dicom._dicom_dict_3 import DicomDictionaryThree
from dicom._dicom_dict_4 import DicomDictionaryFour
DicomDictionary.update(DicomDictionaryOne)
DicomDictionary.update(DicomDictionaryTwo)
DicomDictionary.update(DicomDictionaryThree)
DicomDictionary.update(DicomDictionaryFour)
Search and change the usage of _private_dict.py contents in the pydicom package
Install the package using setup.py
Related
Goal: I have .Key file for preprocessing data file for LS Dyna simulation. From that .Key file, I want to extract certain node numbers lying under certain Part ID (PID).
In order to achieve above goal, I got to know that there is a one python library named 'qd' (https://qd-cae.github.io/qd-cae-python/build/html/qd_cae_dyna_KeyFile.html) which helps to manipulate the key files and extract certain lines according to the Keyword.
However, when I wrote from qd.cae.dyna import *, I got an error ModuleNotFoundError: from qd.cae.dyna import *. Therefore, I tried to install qd in python using pip pip install qd, but I got an error and at the end, this library could not be installed.
My question is:
(1) How can we install qd library in python through Anaconda?
(2) Is there any available python tools or library to read and extract some parameters from the Key files?
I am looking at a code that uses acicobra package. Acicobra library is 670MB. The python code uses only a few functions from acicobra library. Is there a way to install only the required modules from this acicobra library and not the entire library? If I install the entire library, my docker image size gets inflated because of this gigantic library.
root#1f5edb150a78:/usr/local/lib/python2.7/site-packages# ls -l |grep -v dist-info|du -sh *|sort -hr
659M cobra
These are the only references to cobra in the python code
from cobra.mit.access import MoDirectory
from cobra.mit.session import LoginSession, LoginError
from cobra.mit.request import ClassQuery, DnQuery, QueryError
As you can see, the code is referencing only 3 modules out of the entire library.
I am looking for ways to avoid installing the entire library to limit the size of the dockerimage
Not unless it relies on other smaller sublibraries that you can fetch.
You could check out the code and see if you can create your own smaller python package.
But 90% of the time you'll go down a depecdency chain and need the full library anyway.
Also check the license if commercial use.
This should be the correct github for the source:
https://github.com/datacenter/cobra
I am in the process of packaging up a python package that I'll refer to as MyPackage.
The package structure is:
MyPackage/
script.py
data.json
The data.json file comprises cached data that is read in script.py.
I have figured out how to include data files (use of setuptools include_package_data=True and to also include path to data file in the MANIFEST.in file) but now when I pip install this package and import the installed MyPackage (currently testing install by pip from the GitHub repository) I get a FileNotFound exception (data.json) in the script that is to utilize MyPackage. However, I see that the data.json file is indeed installed in Lib/site-packages/MyPackage.
Am I doing something wrong here by trying to read in a json file in a package?
Note that in script.py I am attempting to read data.json as open('data.json', 'r')
Am I screwing up something regarding the path to the data file?
You're not screwing something up, accessing package resources is just a little tricky - largely because they can be packaged in formats where your .json might strictly speaking not exist as an actual file on the system where your package is installed (e.g. as zip-app). The right way to access your data file is not by specifying a path to it (like "MyPackage/data.json"), but by accessing it as a resource of your installed package (like "MyPackage.data.json"). The distinction might seem pedantic, but it can matter a lot.
Anyway, the access should be done using the builtin importlib.resources module:
import importlib.resources
import json
with importlib.resources.open_text("MyPackage", "data.json") as file:
data = json.load(file)
# you should be able to access 'data' like a dictionary here
If you happen to work on a python version lower than 3.7, you will have to install it as importlib_resources from pyPI.
I resolved the issue by getting the 'relative path' to where the package is.
self.data = self.load_data(path=os.path.join(
os.path.dirname(os.path.abspath(__file__)),
'data.json'))
load_data just reads the data file
Any constructive criticism is still very much welcome. Not trying to write stupid code if I can't help it :)
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.
It seems PyInstaller and cx_Freeze will include many packages with an Anaconda2 environment.
Using either will produce a file over 600MB, this is largely due to a chain of includes which eventually includes Numpy, which then includes just about everything else.
An example of the includes that cause 600MB+ worth of packages:
import sys
from sys import argv
from os import path
from Tkinter import *
import tkFileDialog
from PyQt4 import QtCore, QtGui, uic, QtOpenGL
from moviepy.editor import *
Which doesn't seem like much, but I cannot reduce the file down without explicitly excluding Numpy, but even then it's still ~140MB and won't execute.
Has anyone had experience with dealing with this situation? 600MB is well excessive for a tiny app.
This has nothing to do with Anaconda. You will get the same size when you use a standard Python installation.
The reason why your distribution is so big is because of the additional packages you need to supply. A very big chunk is PyQt4. This takes about 250MB of disk space for all the Qt Libraries and the Python bindings. Also as you already wrote numpy takes another big chunk of disk space (250MB on my computer). If you rely on these packages there is not much you can do to decrease the needed disk space.
However you can exclude packages you don't need. I discovered that cx_freeze likes to include packages that are installed in your Python environment regardless if you use them in your project or not. So I recommend to create a virtual environment that only contains the packages you need in your project. Also you may want to exclude tkinter from the build.
This issue was directly related to Anaconda.
When constructing an exe with Pyinstaller, it will get confused at Anaconda's package linkage and include obscene amounts of things.
This problem is fixed when using a non-Anaconda python with wheels for non-pip packages.