Python setuptools package_data - pip fails on subfolders - python-3.x

I am trying to make my own pip package installation to work and I have troubles with subfolders in additional data specified in package_data. Everything seems to be fine (all data are included in produced .zip file), but when I run "pip install myapp", it says: "error: can't copy 'myapp\web\styles': doesn't exist or not a regular file"
Dirtree:
projectDir
setup.py
myapp
__init__.py
webapp.py
web
index.html
styles
style.css
setup.py:
from setuptools import setup
setup (
zip_safe = False,
name = "myapp",
version = "0.1",
packages = ["myapp"],
include_package_data = True,
package_data = {
"myapp": ["web/*", "web/styles/*"]
}
)
Command to create package:
python setup.py sdist
Command to install:
pip install myapp-0.1.zip
I have even try to specify MANIFEST.in (with no success):
include myapp/web/*.*
include myapp/web/styles/*.*
When I specify only MANIFEST.in withou package_data, installation success, but there are no files in site-packages/myapp/web so no package_data were copied.
I am quite desperate because I haven't found any suggestion what I am doing wrong and I have spent long time to make it work.
Thaks for any advice.

Ok, so I have a solution: I have used only MANIFEST.in and removed package_data from setup.py and everything works fine. I thought I have tried this before, but I was wrong.

Related

How to install Gin with Golang

I'm a newbie on Golang, and I'm trying to use Gin to develop a web server on Ubuntu 16.04.
After executing go get -u github.com/gin-gonic/gin, many folders appear at ~/go/pkg/mod/github.com/.
Then I try to make an example:
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
However, go run example.go made the error:
example.go:3:8: cannot find package "github.com/gin-gonic/gin" in any of:
/usr/local/go/src/github.com/gin-gonic/gin (from $GOROOT)
/home/zyh/go/src/github.com/gin-gonic/gin (from $GOPATH)
In my system, $GOROOT is /usr/local/go/ and $GOPATH is ~/go/.
How could I solve this problem?
For Go version 1.11 or newer, You should use Go Modules.
If you are just starting with Go, you should start with the newer version. I think you are using a Go version that supports go modules already because the modules you are trying to get are downloading to ~/go/pkg/mod/ directory.
To initialize a project with go module, run:
go mod init your-project-name
This will create a go.mod file in your project directory.
Add missing and/or remove unused modules:
go mod tidy
This will fill up the go.mod file with appropriate modules and create a go.sum in your project directory. The go.sum contains expected cryptographic hashes of each module version.
After that, the go run example.go command should run the program without any issues.
You can even vendor the modules in your project directory:
go mod vendor
This will bring all the vendors to your projects /vendor directory so that you don't need to get the modules again if working from another machine on this project.
I realized that after adding a package called gopls, my IDE is working perfectly.
Install gopls using snap: sudo snap install gopls --classic
From the error, you can see that GOPATH is your '/home/zyh/go' not your ~/go.
and you can run shell go env to confirm where is your GOPATH? then modify it.

Installing a package with cabal doesn't work (random)

I'm using Windows 10. I downloaded Cabal.exe, put it in my ghc-8.8.1\bin\ directory and ran it with command cabal update. It did nothing for a while, then it ended without any messages.
Now when I run cabal install random (trying to install package "random"), I get the following error:
cabal: Error: Could not find module: System.Random with any suffix:
["gc","chs","hsc","x","y","ly","cpphs","hs","lhs","hsig","lhsig"]. If the
module is autogenerated it should be added to 'autogen-modules'.
I have no clue why it does this.
I also tried installing the package manually (following the steps from here) - downloaded package random-1.1.tar.gz and ran:
cd filepathtopackage
c:\Program Files\Apps\ghc-8.8.1\bin\runhaskell.exe Setup configure
This for a change gives me the following error:
| C:\Program Files\Apps\ghc-8.8.1\lib\Cabal-3.0.0.0\HSCabal-3.0.0.0.o: unknown symbol '.file'
Setup: Setup: unable to load package 'Cabal-3.0.0.0'
When I run ghc-pkg list, Cabal is in there, so again, no clue why it does this.
Does anyone have any tips on how to resolve this?

"Package init file not found (or not a regular file)" - error when building sdist for namespace package

I have a namespace package with folder structure as:
CompanyName\DepartmentName\SubDepartmentName\PkgName
Python 3.3 onwards supports namespace packages so I have not place the __init__.py files in the following folders:
CompanyName
DepartmentName
SubDepartmentName
In the setup.py I have place the following piece of code setuptools.find_namespace_packages() instead of setuptools.find_packages().
When I try to build the sdist, using the following commands:
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools wheel
python setup.py sdist
I get the following error:
package init file 'CompanyName\__init__.py' not found (or not a regular file)
package init file 'CompanyName\DepartmentName\__init__.py' not found (or not a regular file)
package init file 'CompanyName\DepartmentName\SubDepartmentName\__init__.py' not found (or not a regular file)
I have the task setup as part of azure devops pipeline's command line task and have set 'Fail on standard error' to true. The pipeline fails due to the above error.
Though Package init file not found (or not a regular file) is more like a warning than an error locally, it will cause the build pipeline to fail if you set Fail on standard error to true when using VSTS.
Locally:
VSTS with Fail on standard error to default false:
VSTS with Fail on standard error to true:
1.For this, you can choose to turn-off the option(Fail on standard error) cause the python namespace package can be generated successfully though that message occurs. So in this situation, I think you can suppress that message.
2.Also, another direction is to resolve the message when generating the package. Since the cause of the message has something to do with your definitions in your setup.py file, you should use setuptools.find_namespace_packages() like this document suggests.
Because mynamespace doesn’t contain an init.py, setuptools.find_packages() won’t find the sub-package. You must use setuptools.find_namespace_packages() instead or explicitly list all packages in your setup.py.
In addition: It's not that recommended to remove all __init__.py files in packages, check this detailed description from AndreasLukas: If you want to run a particular initialization script when the package or any of its modules or sub-packages are imported, you still require an init.py file.

How can i install missing modules of Python?

First of all I have to admit that I'm a starter. I know there are similar topics like mine. But I couldn't find the proper answer.
I was installing python in my Ubuntu. Downloaded the ‘Python-3.5.1.tar.xz’. And I used the cd command to access this file's path. After that, entered './configure' then 'make'.
It gave me this message:
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _lzma
_sqlite3 _ssl
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Now, how can I install those specific modules ? Thank you.

Error installing Sublime Text 3 Package Control bz2

My ISP in India has decieded to block Github for some reason.I have been trying to install Package Control for Sublime Text 3 both manually and use the Sublime Text 3 Console.In both of the cases,one dependency seems to be missing:
Package Control: Installing 1 missing dependencies
Package Control: Attempting to use Urllib downloader due to WinINet error: Error downloading package. Host not found (errno 12007) during HTTP write phase of downloading https://codeload.github.com/codexns/sublime-bz2/zip/1.0.0.
Package Control: Error downloading package. URL error [Errno 11004] getaddrinfo failed downloading https://codeload.github.com/codexns/sublime-bz2/zip/1.0.0.
error: Package Control
Unable to download bz2. Please view the console for more details.
Package Control: Skipping automatic upgrade, last run at 2015-01-03 11:32:25, next run at 2015-01-03 12:32:25 or after
I have downloaded the Sublime bz2 file manually,what should I do now?
EDIT:
Some skimming through stuff tells me that Package Control 3.0 has dependencies:
Once the package is extracted, a custom-generated python file is added to a special package named
0_package_control_loader. For Sublime Text 3, this is a .sublime-package file, whereas for
Sublime Text 2 it is just a folder. The reason for the name (and creating it as a .sublime-
package file in ST3) is to ensure it is the very first non-default package that Sublime Text
loads.
Is there a version of 0_package_control_loader.sublime-package that I can add manually(given that I have already installed Package Control with this dependency missing?
I've met the same problem as you. Below is the way I resolved it.
Try to get the file "sublime-bz2-1.0.0.zip". (It seems you have done it);
unzip it to the dictory "...\Application Data\Sublime Text 3\Packages\" and rename the sub-dictory name to "bz2".
open a new txt file and paste below code to it
{"platforms": ["*"], "url": "https://github.com/codexns/sublime-bz2/issues";, "version": "1.0.0", "description": "Python bz2 module", "sublime_text": "*"}
save the file to /bz2 and rename its file name as "dependency-metadata.json"
After done these, the hierarchy should be like this:
/Package
├─/bz2
│ ├─/st2_linux_x32
│ ├─/st2_linux_x64
│ ├─/st2_windows_x32
│ ├─/st2_windows_x64
│ ├─/st3_linux_x32
│ ├─/st3_linux_x64
│ ├─/st3_osx_x64
│ ├─/st3_windows_x32
│ ├─/st3_windows_x64
│ └─dependency-metadata.json
└─/User
├─/c2u_tmp
└─/Package Control.cache
restart sublime text3.
Hope it helps!
Regards
This worked for me, see: #godzig's answer, on this related Github issue: issues/989. The gist of it being:
open the 0_package_control_loader.sublime-package archive, in Installed Packages, of your SBT3 folder. Change the filename from 02-bz2.py to 01-bz2.py, and the error is gone; at least in my case anyway.
HTH
I got the same problem and I try and fix it by use manual installation like this:
Manual
If for some reason the console installation instructions do not work for you (such as having a proxy on your network), perform the following steps to manually install Package Control:
Click the Preferences > Browse Packages… menu
Browse up a folder and then into the Installed Packages/ folder
Download Package Control.sublime-package and copy it into the Installed Packages/ directory
Restart Sublime Text
Until your ISP unblocks Github (who does that?), you can download 0_package_control_loader.sublime-package here. I don't know if there are differences in the package for different versions of Windows, but this is from ST3 on Win8. Hope it helps!
Machael Lv's answer didn't help for me.
Then i just started sublime text as administrator for one time and problem dissapeared - now i can run sbt as ussual and error message doesn't appear again.
import urllib.request,os,hashlib;
h = '2deb499853c4371624f5a07e27c334aa' + 'bf8c4e67d14fb0525ba4f89698a6d7e1';
pf = 'Package Control.sublime-package';
ipp = sublime.installed_packages_path();
urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) );
by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read();
dh = hashlib.sha256(by).hexdigest();
print('Error validating download (got %s instead of %s), please try manual install' % (dh, h))
if dh != h
else open(os.path.join( ipp, pf), 'wb' ).write(by)

Resources